Developer forum

Forum » Development » Get current Query parameters and default values in Code Provider

Get current Query parameters and default values in Code Provider

Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi,

 

I am building a code provider and I need to check what a specific parameter (default) value is set for. How can I do that?

 

Here's some pseudo codeof what I'm trying to achieve

public override string BuildCodeString()
{
    if (string.IsNullOrEmpty(MyParameterToCheckFor)
        || Repository.Parameters[MyParameterToCheckFor].ToString().ToLower() != "true")
    {
        return null;
    }
    
    var productIds = GetMyCustomListOfProductIds();
    return string.Join(",", productIds);
}

 

Best Regards,

Nuno Aguiar


Replies

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

bump

 
Nicolai Pedersen
Reply

I don't know. Attach a debugger and see what is available on the base class.

I can't even see what extensibility point you are dealing with... 

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Nicolai,

 

Extensibility point

My extensibility point is for Repository's Code Providers (used in Query expressions). My code is mostly from https://doc.dynamicweb.com/training/t3-platform-developer/t3-platform-developer/3-5-extending-indexing#sideNavTitle1-2-2.

 

Debugger

I attached the debugger to confirm what I had available to me in the base class, but I only have access to the Code Provider's parameters, and what I needed was the current context of the Query (getting the value of a parameter).

 

What am I trying to achieve

This has happened to me twice already. We need to add a Code Provider (query expression) that only triggers when a certain condition is met. For example, the expression could be:

ProductId IN "Custom list of Product Ids"

However the custom list cannot be triggered every time, so we started by doing something like this

public override string BuildCodeString()
{
    if (string.IsNullOrEmpty(QuerystringParameter)
        || Dynamicweb.Context.Current.Request.QueryString[QuerystringParameter]?.ToLower() != "true")
    {
        return null;
    }
    
    var productIds = GetCustomListOfProducts();
    return string.Join(",", productIds);
}

This works great, meaning that the expression is disregarded if the QuerystringParameter is not in the querystring.

My final step was to change it from a Querystring parameter to a (Repository) Query parameter

Then on a Paragraph I can override the default value of "MyCustomParameter" and that would trigger the expression - This is what I can't get to work easily (without the workaround at least)

 

Workaround

  1. I believe I found a workaround. I can get the current page (not the current paragraph), so from it, I can get the page's paragraphs that contain the Product Catalogue/Query Publisher App, and get the values defined in the paragaph module settings.
    OR
  2. Customize the feed request and ensure that "MyCustomParameter" is submitted as a querystring parameter, but my goal was to conditionally trigger an expression without customization on the templates (only UI settings).

 

The ability to conditionally trigger expressions if a query parameter = X has come up a few times now. Maybe in the future there would be a nicer way to do this, but for now as long as I can get this to work I'm good.

 

I hope this makes sense. 

 

Best Regards,

Nuno Aguiar

 

You must be logged in to post in the forum