Record is getting populated in servicenow widget customization

abhi56
Tera Contributor

i am using two widget from 1st widget i am calling the 2 nd widget 

 

1st widget :calling the second widget and want to pass some paramter(it is actually a value) using this code ,

 
 
data.insid=input.selectedRecord;
        var myinput={
            instance:data.insid,
        };
        gs.addInfoMessage(typeof(input.selectedRecord));
    data.catitem = $sp.getWidget('mysurvey',myinput);
 
 
then in 2nd widget server script i am trying to retrive the value :using this code
 
gs.addInfoMessage("Options instance_id: " + options.instance_id);
//options.instance_id='6b70cfae872a5a5474b385130cbb3570';
    var page_id = 'bsurvey';
    var typeId = options.type_id || $sp.getParameter('type_id') || "";
    var instanceId = options.instance_id;
    gs.addInfoMessage("var instance_id: " + typeof(instanceId));

 

now the problem is when i showing info message i am getting the same value as a type string ,and using that in the var instanceid ,the particular record is not opening,showing you are not authorized or record is not validcommunity 4.PNG

but when i am putting it as hardcoded value then it is taking the value correctly and populating the record 

 

1 REPLY 1

Juhi Poddar
Kilo Patron

Hello @abhi56 

Since you are already getting the sys_id in 2nd widget, try this:

gs.addInfoMessage("Options instance: " + options.instance);
var instanceId = options.instance;
gs.addInfoMessage("Instance ID: " + instanceId);

if (instanceId) {
    // Retrieve the record here using the instanceId
    var record = new GlideRecord('your_table');
    if (record.get(instanceId)) {
        gs.addInfoMessage("Record retrieved: " + record.getValue("sys_id"));
    } else {
        gs.addInfoMessage("Record not found or invalid.");
    }
} else {
    gs.addInfoMessage("Instance ID is not valid.");
}

There is another concept broadcast and rootscope to pass data from one widget to another. 

You can refer this video to understand more about it: broadcast and rootscope

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps others find the solution more easily and supports the community!"

 

Thank You
Juhi Poddar