Glide List update from a client script

Fabio Cresta
ServiceNow Employee
ServiceNow Employee

Hi All.

I'm preparing a PoV and getting crazy in trying to update a Glide List via a client scritp.

Here's the context:

1. I select 2+ demands from the dmn_demand table

2. I launch an UI action that reads some info from the selected demands (specifically the companies each demand is linked to)

3. I open pm_project.do page passing the companies list sysIds comma separate in the URL to create a new project

4. in the project I defined an onLoad client script that reads the companies list (I check and it's correct)

 

In the script I added: 

   g_form.setValue('u_companies', <sysIds list>)

but the attribute is always empty.

The same works with other attribute types.

 

Here's my code. All works except the last setValue.

Any hint?

Thanks

 

function onLoad() {

   //Type appropriate comment here, and begin script below
   if(g_form.isNewRecord()){

        var url = new GlideURL(window.location.href);

        g_form.addInfoMessage('u_companies ' + url.getParam('u_companies'));

        g_form.setValue('start_date', url.getParam('start_date'));
        g_form.setValue('end_date', url.getParam('end_date'));
        g_form.setValue('u_orig_demand', url.getParam('u_orig_demand'));
        g_form.setValue('u_product_line', url.getParam('u_product_line'));
        g_form.setValue('u_product_item', url.getParam('u_product_item'));
        g_form.setValue('u_unit_of_measure', url.getParam('u_unit_of_measure'));
        g_form.setValue('u_quantity', url.getParam('u_quantity'));
        g_form.setValue('u_companies', url.getParam('u_companies'));
   }
}
2 REPLIES 2

PratikshaKate
Tera Contributor

Hi @Fabio Cresta I found something related to this but it is using flow. You can check it out using the link below:

Solved: How to push new values to a list (glide_list) type... - ServiceNow Community

 

Mark my answer helpful if it helped you 🙂

YaswanthKurre
Giga Guru

HI @Fabio Cresta ,

 

While you are building the URL from demand table try to encode companies before you add it to URL:

 

example snippet:

var companies = 'sys_id1,sys_id2,sys_id3';
var encodedCompanies = encodeURIComponent(companies); //add this to urlfor u_companies

var url = 'https://yourinstance.service-now.com/pm_project.do?u_companies=' + encodedCompanies;

 

Try this and let me know if this helps.

 

Thanks