Need Background script for changing a field value

AnandKumar1
Tera Expert

Hi Team,

Good Day!!

I need a background script for changing a field (Task type) value (from Test to Post-Work).

We dont have field value in numbers as like in Incident.Attached the screenshots.find_real_file.png

 

find_real_file.png

Please check . the script is not working as it takes any value given other than Test,Work,Pre-Work,Post-Works too.

1 ACCEPTED SOLUTION

AbhishekGardade
Giga Sage

Hello Anand,

We are using IN operator if we want to find numbers from comma separated values provided in query.

For example.

ctask.addQuery('number','CTASK0753800,CTASK0753801,CTASK0753802');

As you need to find it for single ctask, then either you can use addQuery without IN,

var ctask = new GlideRecord('change_task');

ctask.addQuery('number','CTASK0753800');

ctask._query();

if(ctask._next()) {

ctask.u_type="Post-Work";

ctask.setWorkflow(false);

ctask.update();

}

Please mark as Correct Answer and Helpful, if applicable.
Thank You!
Abhishek Gardade

Thank you,
Abhishek Gardade

View solution in original post

5 REPLIES 5

Elijah Aromola
Mega Sage

Change it to "ctask.u_type='Post-Work'", if that value is correct you're missing the quotations.

Please mark this as helpful/correct if it resolved your issue!

Mark Roethof
Tera Patron
Tera Patron

Hi there,

I've re written your script a bit. number IN doesn't sound logical. I would hope you only have one change task with that number?

Performing a while, why? You are only updating one record right?

setWorkflow(false), up to you offcourse, I don't know your further specs.

var ctask = new GlideRecord('change_task');
ctask.addQuery('number', 'CTASK0753800');
ctask._query();

if(ctask._next()) {
	ctask.u_type="Post-Work";
	ctask.update();
}

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Did this solve your question? Or do we need to follow-up on this?

Please mark this answer as correct if it solves your question. This will help others who are looking for a similar solution. Also marking this answer as correct takes the post of the unsolved list.
Thanks.

Kind regards,
Mark

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

asifnoor
Kilo Patron

Hi,

Try this code. 3 corrections made.

1. IN is not required

2. add quotes to your u_type value.

3. while is not required as you are updating only 1 record. 

var ctask = new GlideRecord('change_task');
ctask.addQuery('number', 'CTASK0753800');
ctask.query();
if(ctask.next()) {
  ctask.u_type="Post-Work"; 
  ctask.update();
}

Mark the comment as a correct answer and helpful once worked.