Developer forum

Forum » PIM » User Macro in Queries used for feeds

User Macro in Queries used for feeds

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

I have a project where we have built a UserMacro that is supposed to return a list of ProductNumbers that the user is not supposed to see.

The User Macro is used in regular product Queries and it works pretty fine.

However, when applying it to the Query used for generating User-specific feeds, it seems that the User Macro is not returning anything.

I suppose that dwapi is not honoring the code for the UserMacro. Is there a way I can accomplish my objective to filter the query used for the feed based on some user-related info?

Thank you,

Adrian

 


Replies

 
Nicolai Pedersen
Reply

Remember that there is no context when running a feed - so there is no session, and you need to get hold of your user in a way that takes that into consideration.

The feed has the userid as part of the request - so make a conditional to find the correct user. 

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

Thank you for the details. I was expecting this to be the reason behind the issue.

I will have to make the changes in the code somewhere because I am using an XSLT for the transformation.

Thank you,
Adrian

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

One more thing. Where would I make this type of customization? As I have mentioned, I am using an XSLT to transform the output.

Should I switch to Template or I can hook into the API with some custom code?

Thank you,
Adrian

 
Nicolai Pedersen
Reply

Can you share a bit more on exactly your setup is?

The feed, the template/xslt and how you call it.

Thanks, Nicolai

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,

it is a PIM feed based on a Query:

With a few Settings:

The query has an additional filter based on a Macro that returns a list of ProductNumbers (stored in a custom table):

Apart from the UserMacro and the customization I've made in the XSLT, it's pretty standard.

Prices are based on PriceMatrix in DW (initially we have tried fetching the prices Live but we dropped it).

That's all about it.

I have a Dev solution if you wanna poke around: http://dev.gf.dotfusion.ro/

Thanks,
Adrian

 
Steffen Kruse Hansen Dynamicweb Employee
Steffen Kruse Hansen
Reply
This post has been marked as an answer

Hi Adrian,

If you just want to get the UserId which is set on the feed inside the Macro, you can just replace your call to 'User.GetCurrentExtranetUser' with this instead:
            var encryptedUserid = Context.Current.Request.Params["UserId"];
            var userid = Dynamicweb.Security.SystemTools.Crypto.Decrypt(encryptedUserid);

It's not pretty, but it works in the feed :)

Best regards,

Steffen

Votes for this answer: 1
 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Steffen,

Thank you. I already use that part in another feed for another project.

In my case, I need to filter the query. And my Macro is based on the user but it returns a list of ProductNumbers from a custom table.

I guess I will have to create a method that I can use in the XSLT and include your suggestion in it.

I don't have any other idea right now.

Thank you,

Adrian

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Guys,

I have implemented the solution suggested by Steffen and it works well except for some very strange behavior that I cannot understand.

For some reason, only if I change the name of SupportedActionsInternal action that is called, I could make it call again and work as expected.

Maybe there is some sort of caching that prevents Evaluate function to call?

It works right now (after a few changes to the name every time I made an adjustment to the code) but it would be useful to understand the behavior for future developments.

Thank you,
Adrian

 

You must be logged in to post in the forum