How to pass the variable value in redirect URL

rmaroti
Tera Contributor

Hello Everyone,

 

I have requirement  when on select of "Learning" reference variable value which is one of the value of different table on current record producer it will redirect to another record producer which has same reference variable in redirect record producer which is working for me but I want populate default value "Learning"  for the same reference variable in redirect record producer only in case of redirect another record producer.

 

I have attached screenshot Please look into those I have highlighted in screenshot where I'm expecting learning default value only at the time of redirect from another record producer.

 

OnChnage Catalog client script-

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var top = g_form.getValue('topic_category');
    if (top == '3c17157d1be80950b5ce9608b04bcbed') // sys_id of "Learning" value
{
        location.href = 'https://rbassisttmp.service-now.com/peoplehub?         id=sc_cat_item&sys_id=839689bb1bcab890b5ce9608b04bcb9d'; // Redirect URL of another record producer
    }
    

}
 
 
 
Note- can we pass on the "What is this request regarding?" reference variable value as "Learning" in same URL of redirect record producer.
10 REPLIES 10

_Gaurav
Kilo Sage

Hi @rmaroti 

Can you try the below-mentioned code if that works for you?

  location.href = 'https://rbassisttmp.service-now.com/peoplehub?         id=sc_cat_item&sys_id=839689bb1bcab890b5ce9608b04bcb9d'+'variable_value='+g_form.getValue('what_is_this_request_regarding');

And once you redirected to another RP, you can write the onLoad script to get the value of variable_value using getParameter method.

Please mark this as helpful if this resolves your query and hit accepted as a solution.

Thanks!

rmaroti
Tera Contributor

@_Gaurav 

 

can you sent me the code for get the value of variable_value using getParameter method.

 

 

@rmaroti 

Try this,
This onLoad should be written in the redirected record producer to get the value from the parameter only when it's been redirected from the previous record producer

if(getParameterValue('learning')=='Yes') //I am assuming the learning keyword is coming from the previous record producer

{
      g_form.setValue('field_of_redirected_record_producer','learning');   
}
    function getParameterValue(name) {
        var url = top.location.href;
        var value = new URLSearchParams(url).get(name);
        if (value) {
            return 'Yes';
        }
        else{
            return 'No';
        }
    }
}

rmaroti
Tera Contributor

Below is Onload client script:

function onLoad() {


    if(getParameterValue('learning')=='Yes') //we assuming the learning keyword is coming from the previous record producer

{
      g_form.setValue('what_is_this_request_regarding','Learning');  
}
    function getParameterValue(name) {
        var url = top.location.href;
        var value = new URLSearchParams(url).get(name);
        if (value) {
            return 'Yes';
        }
        else{
            return 'No';
        }
    }
}

and previous record producer onChange client script is:
function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var top = g_form.getValue('topic_category');
    if (top == '3c17157d1be80950b5ce9608b04bcbed') {
          location.href = 'https://rbassisttmp.service-now.com/peoplehub?id=sc_cat_item&sys_id=839689bb1bcab890b5ce9608b04bcb9d'+'learning'+g_form.getValue('what_is_this_request_regarding');
    }
   

}
 
but it showing 'You are either not authorized or record is not valid' this error