- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2022 06:18 AM
Dear all,
I created a catalog item to Create New or Update Existing record on the table name Company [core_company].
There are 3 variables:
- Create New or Update Existing - Multiple Choice
- Current Manufactory - reference to Company [core_company]
- New Manufactory - Single Line Test
Note that: the field that need to update/create new in theCompany [core_company] table call name.
I created the following workflow script to update/create new record somehow it is not working.
var mft = current.current_manufacturer_name; if (gr.next()) { |
I would appreciate your help.
Regards,
Hong
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2022 07:13 AM
Hello,
Please see my last reply, above.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2022 07:02 AM
Hi,
As I've mentioned above, you really should be adding logging statements your code otherwise you're just coding in the dark.
Please double-check the variable name you are using.
If the variable is a reference field, then you'd be getting the sys_id and instead need to use:
gr.addQuery('sys_id', mft);
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2022 07:11 AM
Hi Allen,
I have removed that line and updated the script but it is working.
New Script:
var mft = current.variables.current_manufacturer_name;
var gr = new GlideRecord('core_company');
gr.addQuery('name', mft);
gr.query();
if (gr.next())
{
gr.name = current.variables.new_manufacturer_name;
gr.setWorkflow(false);
gr.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2022 07:13 AM
Hello,
Please see my last reply, above.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2022 07:15 AM
Hi Allen,
You are right. It is working now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2022 06:26 AM
Hi
I cannot reproduce your code and therefore you hopefully have tested it in a background script before.
Two important things are to mention:
(1)
Remove current.setAbortAction(true);
This is nothing for workflows!
(2)
Before calling gr.update(); you have to insert gr.setWorkflow(false); or you risk huge problems due to endless loops. Remember: Each update can start additional Workflows/Flows/Business Rules!
Kind regards
Maik