Scripting Query

Priyanka Thadib
Tera Contributor

Hi All,

 

We have two service offerings as below.

 

Candidate Hotel

Hotel Active

 

If any location is listed on both offerings ('service_subscribe_location' table), the location should be removed from the "Candidate Hotel" service offering.

 

And in future also, if any new location is added for "Hotel Active" service offering, it should check "Candidate Hotel" service offering and remove from there.

 

Could you please help me on this?

 

Thanks & Regards.

 

 

1 ACCEPTED SOLUTION

Community Alums
Not applicable

Hi @Priyanka Thadib 

We can use of following script in After BR when record is created/update on service_subscribe_location' table.

 

polnilesh99_0-1737720068402.png

 

View solution in original post

2 REPLIES 2

Community Alums
Not applicable

Hi @Priyanka Thadib 

We can use of following script in After BR when record is created/update on service_subscribe_location' table.

 

polnilesh99_0-1737720068402.png

 

amaradiswamy
Kilo Sage

you may write the Async business rule to acheive this.

 

Name: remove location for CandidateHotel

Table: service_subscribe_location

Advanced: true

Active: true

When to run:

When: Async 

insert -- true

update -- true

Filter conditions:

Service offering is Hotel Active [OR]

Service offering is Candidate Hotel

Advanced:

Script:

 

(function executeRule(current, previous /*null when async*/) {

	var gr = new GlideAggregate('service_subscribe_location');
	gr.addQuery('service_offering=SYSIDOFCANDIDATEHOTEL^ORservice_offering=SYSIDOFHOTELACTIVE^cmn_location='+current.getValue('cmn_location'));
	gr.addAggregate('COUNT');
	gr.query();
	if(gr.next())
	{
		if(gr.getAggregate('COUNT') >=2)
		{
			var gr2= new GlideRecord('service_subscribe_location');
			gr2.addEncodedQuery('service_offering=SYSIDOFCANDIDATEHOTEL^cmn_location='+current.getValue('cmn_location'));
			gr2.query();
			if(gr2.next())
			{
				gr2.deleteRecord();
			}
		}
	}

})(current, previous);