g_form.SetValue() not working in Service Portal (Kingston patch3)

Ayushi Agarwal
Kilo Contributor

Hi Everyone,

I am using a basic g_form.setValue function for a catalog item variable.

Eg:-

function onLoad() {
//Type appropriate comment here, and begin script below

//var a = g_form.getValue('test_name');
g_form.setValue('comments',new Date());
//alert(g_form.getValue('choice'));
}

When I test the catalog item from the Service Catalog, this code is working. However, when trying to test within Service Portal, it's not able to set up the field values.

I tried hardcoding the value and even use the values of some other field, but it is not populating the field on the service portal.

Note: Our instance recently upgraded to Kingston.

Kindly suggest a solution for this.

17 REPLIES 17

Hi Rudi Can you please share your code? I don't see GlideRecord in your original post. Are you using GlideRecord to update existing record? My use case is to update existing record with record producer via populating values on the form or I might use form widget for that.

Hi, sorry for the late reply. The GlideAjax we have added calls a script include to retrieve server values.

 

You can look at the following:

 

https://docs.servicenow.com/bundle/helsinki-application-development/page/script/server-scripting/reference/r_GlideAjax.html

Regards

apjohn2
Mega Sage

I'm struggling with this too and I'm on Kingston patch 6 in both Dev and Test where this issue is occurring. This is the most recent patch available as I write this, so it's not fixed yet apparently.

I've had partial success using setValue on some types of variables but its behavior on checkboxes is broken.

I'm using a very simple Catalog UI Policy that should set one checkbox 'skype' to true if another checkbox 'email_account' is set to true. The policy is set to run in 'All' UI types.

It appears that what it's doing in the portal is very rapidly applying the 'true' value to the checkbox (as evidenced by noticing that a separate policy to show a third option does in fact get triggered, and only gets triggered by the target checkbox being set to 'true'), but the 'true' setting on the target 'skype' field is not staying put.

It works fine in ESS.

I'm calling HI now to find out more. Maybe this is in Patch 7. /shrug

apjohn2
Mega Sage

HI support pointed me to this page and explained that I need to add quotation marks around the 2nd parameter, even though it's a Boolean value.

So I changed my Policy script from this...

function onCondition() {
	g_form.setValue('skype',true);
}

to this...

function onCondition() {
	g_form.setValue('skype','true');
}

And it worked just fine.

They also noted that it wasn't always this way, and "created PRB1290254 to have this issue addressed, since there was a change in behavior." And a bit later the gentleman working the case called and said he expects to be publishing a KB about this too. 🙂

Meanwhile I hope this helps others w/ this issue. (Ayushi - feel free to mark this is the correct answer of course if it helped you.)

Anil Lande
Kilo Patron

Hi All,

I a also facing same issue on portal, particularly on dot walked fields. 

We are on patch 7 but issue persist.

 

Any help would be appreciated!

 

Thanks,

Anil 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande