Set boolean flag via background script

sunil4050
Giga Contributor

In the holiday calendar cmn_schedule_span table there is a field "All Day" which is boolean. I am trying to update it from transform map as well as background script but unable to . Request you to please let me know if i am doing something wrong here

 

var gr = new GlideRecord('cmn_schedule_span');
gr.addEncodedQuery('sys_created_by=xxxxx');
gr.query();
while (gr.next()) {
gr.all_day=true;
//gr.type='exclude';
//gr.show_as='busy';
gr.update();
gs.print("Opened By==" + gr.all_day);
//gr.deleteMultiple();
}

1 ACCEPTED SOLUTION

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
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

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

View solution in original post

7 REPLIES 7

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Have you tried adding setWorkflow(false)?

Something like this:

(function() {

	var gr = new GlideRecord('cmn_schedule_span');
	gr.addEncodedQuery('sys_created_by=xxxxx');
	gr.query();
	
	while(gr.next()) {
		gr.all_day=true;
		gr.setWorkflow(false);
		gr.update();
	}

})();

Obviously, this might cause that the cmn_schedule records are not updated. So you could also have a look which Business Rules, etc. are causing some records not to be updated without setWorkfow(false).

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

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

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

Pooja Mallikarj
Kilo Sage

Hi,

Yes,as Mark Roethof suggested you need to use setWorkflow(false) in order to avoid other BR running on same table.

try with below code.

var gr=new GlideRecord('cmn_schedule_span');
gr.addEncodedQuery('sys_created_by=xxxx^active=false');
gr.query();
while(gr.next())
{
gr.all_day=true;
gr.setWorkflow(false);
gr.update();

}
gs.print('updated');

 Thanks,

Pooja M

Chander Bhusha1
Tera Guru

Hi sunil4050,

You cannot set that field to true or false using any script(background or fix script). You have to do it manually.This field is not like a normal True/false field. Its something different

We had this requirement earlier but ended up in doing it manually as we couldn't find the solution for that.

 

Mark helpful and correct if it helps.

Thanks,

CB

 

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
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

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