Want to write a FIX script for updating a field

Sayan
Mega Contributor

I want to write a fix script for doing a bulk update in the indicator task table into a particular field.The table is IDT. The tasks are already closed, so the field is grayed out. Below is the code that I have written.

var gr = new GlideRecord('table name');
gr.addEncodedQuery('the query for the tasks that needs to be updated.');
gr.query();
while(gr.next()){
gr.fieldname = "the update";
gr.setWorkflow(false);
gr.update();
}

After I run the script I find that no changes has happened in the required field. It still shows blank.

Any help will be appreciated.

1 ACCEPTED SOLUTION

Hello Sayan,

I hope you are actually running the correct code. This below code will not work as is. you need to place right field names and right queries.

var gr = new GlideRecord('table name');
gr.addEncodedQuery('the query for the tasks that needs to be updated.');
gr.query();
while(gr.next()){
gr.fieldname = "32 digit sys_id that you need to update";
gr.setWorkflow(false);
gr.update();
}

Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.

Regards,
Asif
2020 ServiceNow Community MVP

View solution in original post

8 REPLIES 8

Allen Andreas
Administrator
Administrator

Hello,

Unfortunately, you aren't providing any precisely what you're doing and instead showing just what would be the example you'd follow...while that's nice, we know that. We need to know what YOU did. Specifically.

Like...what is the update you are doing to "fieldname"...? is it string? Is it a reference field?

Did you do any log entries to see what that field would be after you set it? like:

gs.log("This will be the new value: " + gr.fieldname);

So you'd put that after you set the field to that value and before the update, just to see if the system recognizes it there. If it still doesn't update after that..then we can get in to why that might be. Like using gr....which could be reserved and used elsewhere at that same moment thus gr won't work.

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


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

HI Allen,

 

I am trying to run the above code that I have written. I have also tried the gs.log, which shows that the correct value that I want to update but its just not updating in the form field. 

It is a reference field. The value with which I want to update with is a value from that reference field only. The value is same for the all the tasks that I want to update.

Thank you.

Glad you got your answer...as I mentioned, we needed more information. You've also posted this question about 5 times?

Then the same person copies and pastes their answer to it, which is not the correct way to handle this. The others need to be deleted.

Also other posts...need to be marked as Helpful, if they were...like...did my post not HELP reveal that it was a reference field due to you not mentioning it in your original post?

Anyways...

Take care


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

Sayan
Mega Contributor

HI Allen,

 

I am trying to run the above code that I have written. I have also tried the gs.log, which shows that the correct value that I want to update but its just not updating in the form field. 

It is a reference field. The value with which I want to update with is a value from that reference field only. The value is same for the all the tasks that I want to update.

Thank you.