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, We are using a callback function with ref fields.

example:

 

 

function onLoad() {

	var user_ref = g_form.getReference('u_requested_for', loadInfo);

function loadInfo(user_ref) {
g_form.setValue('u_user_id', user_ref.user_name);

} 
}

Regards

manishm
Mega Guru

For the benefit of others -

Works fine with g_form.setValue(fieldname,'true') - Notice the true in quote as pointed by ajohnson_lci. However, if the value is being reset to false, the quotes are not required. 

Also, does not work with a UI policy script at all (quotes or otherwise). I had to use a change client script with UI type of ALL to get this working on the portal. 

Manish

Alexander Ander
Tera Contributor

Seems to be a timing problem with angularJS. Using a setTimeout call seems to fix it;

You'll want to change

g_form.setValue('comments',new Date());

to

setTimeout(function() {
    g_form.setValue('comments',new Date());
}, 0);

Essentially pushing the setValue call to the next execution stack so that the value set happens after the AngularJS evaluation finishes.