Issue with save in OnLoad Client Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-04-2017 07:22 AM
Hi All,
There is a catalog Item which has Date variable, while user selecting the date as 04-06-2016, its changes into 0007-08-06. And it's not consistent. To get the rid of this problem I have created another variable as single line text and copy the value of user's selection on Date field and paste it there. Which is working fine.
And onLoad of that Requested Item, I am placing it back to Date Variable. The problem is that whenever user open the RITM page, the date field gets changed and if user navigate to other page then it asking to save that page.Therefore, I have applied g_form.save() line.
I would like this to be happen only once. Below is the line of code however save is going on loop and i want to execute only once.
Could anyone of you please let me know how do i restrict the save to execute only once?
Quick reply must be appreciated.
function onLoad() {
var required_date = g_form.getValue('variables.u_date');
if (required_date != '') {
var boolea = true;
if(bool)
{
g_form.setValue('variables.u_req_date',required_date);
g_form.setDisplay('variables.u_date', false);
g_form.save();
boolea = false;
return;
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-04-2017 11:11 AM
For the looping, I would wager a guess that the g_form.save() creates a post back that reloads the form, which in turn runs the onLoad script again. Any navigation action aborts the current script and variables do not persist across script calls, so trying to save a boolean within on load won't help.
What is the date format of the system and the user opening the form? Not sure if this is related, but here is a KB about Service Portal having issues when the date format is anything other than yyyy-MM-dd.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-04-2017 11:19 AM
Hi Everyone,
Thanks for your response.
Actually, I already opened a ticket with SN to find out the root cause of it. In mean time, I am trying to place workaround and stuck with this save function going on loop.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-04-2017 11:28 AM
Do not call g_form.save() in an onLoad, post-back creating onLoad loop.