Create/Update record thru workflow script

hongsok
Tera Contributor

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;
var gr = new GlideRecord('core_company');
gr.addQuery('name', mft);
gr.query();

if (gr.next())

{
current.setAbortAction(true);
gr.name = current.new_manufacturer_name;
gr.update();
}

I would appreciate your help.

 

Regards,

Hong

 

 

1 ACCEPTED SOLUTION

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!

View solution in original post

11 REPLIES 11

Allen Andreas
Administrator
Administrator

Hello,

To get any variable name in workflow script, you'd need to use the format:

current.variables.variable_name

Please check your script for proper formatting and context.

As far as GlideRecord is concerned, here's the documentation to help you with that if you're still facing issues: https://developer.servicenow.com/dev.do#!/reference/api/paris/server/no-namespace/c_GlideRecordScope...

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Let me try.

Hi Allen, 

No luck.

Hi,

My reply above was specifically about the incorrect usage of how you were trying to get the variables. Your format was not correct, what I'm saying is correct, in that regard.

As far as anything else, if your script in trying to run as that user, do they have appropriate "write" privileges? Are you testing this as yourself? As a specific user?

Also why do you have: current.setAbortAction(true); in your script?

These and other things are beyond just the question that you asked that we don't know anything about.

Please explain more fully what you were thinking and/or wanting to do, why that code is there, what else are you doing to assist this troubleshooting process? I see no troubleshooting logs, etc.

Simply writing back "no luck", is not helping us.

Sorry!

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!