- 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:28 PM
Hi,
so any existing record if you open your script is running?
ideally it should not since you have given isNewRecord()
did you check what comes in g_form.isNewRecord() in alert?
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:50 PM
Hi
The scripting is running fine and it is not clearing any values of the fields when I open existing record, which is created manually. The scripting is clearing the field value of an existing record, which is created via Workflow.
When i am opening the new record, then g_form.isNewRecord() is giving the value true. So it is executing the if block statements. And for existing records, g_form.isNewRecord() is giving the value false, so it is executing the else block statements.
Hope I have answered your queries.
Regards,
Yesh
- 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-23-2022 12:04 AM
Any update on this?
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-23-2022 01:28 AM
Hi
It got resloved. I have created another client script to run for the existing record.
Thanks
Yesh