g_form.SetValue() not working in Service Portal (Kingston patch3)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2018 02:22 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-17-2018 06:10 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2019 08:22 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2019 08:00 PM
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.