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

Hi @rmaroti 

Sorry my bad, I missed a small thing over here.

OnChange script on first record producer

 

top.window.location = 'https://rbassisttmp.service-now.com/peoplehub?id=sc_cat_item&sys_id=839689bb1bcab890b5ce9608b04bcb9d'+'&learning'+g_form.getValue('what_is_this_request_regarding');'
 
OnLoad script on the second record producer
 
function onLoad() {
if(getParameterValue('learning')=='Yes'){
{
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';
}}}
 
Try this, this will run. I checked in my instance and running correctly.

Please mark this as helpful and accept it as a solution if this works for you.
Thanks!

rmaroti
Tera Contributor

@_Gaurav  it is redirecting perfect but not setting "Learning" value on another record producer.

OnChange Script on First RP-

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var topic = g_form.getValue('topic_category');
    if (topic == '3c17157d1be80950b5ce9608b04bcbed') {
          top.window.location = 'https://rbassisttmp.service-now.com/peoplehub?id=sc_cat_item&sys_id=839689bb1bcab890b5ce9608b04bcb9d'+'&learning'+g_form.getValue('what_is_this_request_regarding');
    }
}
 
OnLoad script on the second record producer
function onLoad() {
    if (getParameterValue('learning') == 'Yes') {
        {
            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';
        }
    }
}
 
please find attached screenshot not mapping learning value in  another record producer.

@rmaroti 
In the second record producer, please make sure the backend value of "Learning" is "Learning". May be this could be the reason for not setting the value in the variable.

Also, try to add some delay in your onLoad CS

setTimeout(function(){               

g_form.setValue('what_is_this_request_regarding', 'Learning');

}, 5000);

//Here 5000 indicates 5sec of delay, you can make the change in the timing accordingly.

Hi @rmaroti 
Please mark this as helpful and accept it as a solution if this works for you.
Thanks!

rmaroti
Tera Contributor

im using this one but not working my value_name is"Learning"

code is -

function getParameterValue(name) {
var url = top.location.href;
var value = new URLSearchParams(url).get(name);
if (value) {
return value;
}
if (!value) {
var gUrl = new GlideURL();
gUrl.setFromCurrent();
value = gUrl.getParam("sysparm_id");
return value;
}
}