- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2022 09:10 PM
Hi Team,
I am trying to insert a new record into the table via Workflow, It is getting inserted properly. But clearing one Field value, whenever i open that record. When I am trying to insert the new Record manually, then it is not clearing any field value when the form loads. The Client script which is clearing the Field value is below:
function onLoad() {
//for the new record form load all approved periods. For existing record, load with selected period
if (g_form.isNewRecord()) {
var approvedPeriod = new GlideAjax('Journal_ClientUtil');
approvedPeriod.addParam('sysparm_name', 'getPeriodName');
approvedPeriod.addParam('sysparm_cUserId', g_user.userID);
approvedPeriod.getXML(PeriodResponse);
} else {
var month = g_form.getValue('u_month');
var year = g_form.getValue('u_year');
g_form.clearOptions('u_month');
g_form.clearOptions('u_year');
if (month != '' && year != '') {
var arrayMonth = new Array("indexoccupier", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
g_form.addOption('u_month', month, arrayMonth[month]);// It is clearing this Month Field Value
g_form.addOption('u_year', year, year);
}
}
}
Is there any way to fix this issue?
Thanks,
Yesh
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2022 11:40 PM
Hi,
So there will be 2 records
1) which is already created from workflow and you open it; it should give g_form.isNewRecord() -> false
2) which is created manually now and it's a new one; it should give g_form.isNewRecord() -> true
What's your case?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2022 09:24 PM
In the else condition, you have g_form.clearOptions, so this is executing on onLoad client script and clearing the options available for the choice field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2022 10:00 PM
Hi,
Yes. You are right, It is clearing the options. But I am adding the options by checking the condition right. So that is why, it is adding the options for the existing record, which is created manually. But it is not adding the options for the existing record, which is created via workflow.
Regards,
Yesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2022 10:11 PM
That might be suggesting, the if condition that you have put (if (month != '' && year != '') {), is not running for records created via workflow. Can you check this once and confirm. What are the values for month and year for records created via workflow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2022 10:24 PM
Hi,
When you add choices using client scripts, the choice sys_id is different every time.
Every time records are created in workflow through scripts, they have the same sys_id. Whenever you open an existing record, your client scripts first clear the choices and add new choices through your array. it is not saved.
Thus, it is clearing the options.
Thanks!
Sagar Pagar