- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2017 02:41 AM
Hi All,
We have Service Offerings related to Contracts, I'm setting up a business rule that will mark the contract as Inactive is the related Service Offerings are Ceased.
Thus far i am working with this script:
var gr = new GlideRecord('service_offering');
gr.get('contract', current.sys_id);
if (gr.u_billing_status == 'Ceased'){
current.u_billing_status = 'Inactive');
}
else current.u_billing_status = 'Active';
This works when there is just 1 service offering but if there are 2 and 1 is Ceased the contract is marked as Inactive when it should still be Active. Also, when the status of the related Service Offerings change there is no direct change to the Contract so the business rule is not triggered.
So, i need a way to say 'Mark as Inactive only when all associated Service Offerings are Ceased' and i also need a way of triggering the business rule on the Contract without having to make a change to the Contact.
All assistance welcomed
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2017 03:42 AM
Hi Dave,
If this doesn't work, try following
var so = current.getValue('contract');
var con = new GlideRecord('ast_contract');
var ser = new GlideRecord('service_offering');
ser.addQuery('contract', so);
ser.addQuesry('u_billing_status','!=' ,'Ceased');
ser.query();
if (con.get(so))
{
if (ser.hasNext())
{
con.u_billing_status = 'Active';
}
else
{
con.u_billing_status = 'Inactive';
}
}
con.update();
Raj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2017 03:42 AM
Hi Dave,
If this doesn't work, try following
var so = current.getValue('contract');
var con = new GlideRecord('ast_contract');
var ser = new GlideRecord('service_offering');
ser.addQuery('contract', so);
ser.addQuesry('u_billing_status','!=' ,'Ceased');
ser.query();
if (con.get(so))
{
if (ser.hasNext())
{
con.u_billing_status = 'Active';
}
else
{
con.u_billing_status = 'Inactive';
}
}
con.update();
Raj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2017 03:55 AM
Raj you truly are a King!
The if (ser.hasNext)) line has fixed everything, it's all working perfectly now.
Thanks a lot for your help on this, it's very much appreciated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2017 04:23 AM
Cheers Dave

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2017 04:25 AM
Hi David,
To make it very simple for understanding as well as coding lets start it again.
You have to write a BR on Service Offering table which will be triggered when ever it is Ceased and which will check if there is any other non-Ceased Service Offering with the Contact used. If there is no other found then you can simply mark the Contract inactive.
Below is the BR you need.
Name: Mark Contract Inactive
Table: Service Offering [service_offering]
Advanced: true
When to Run: After
Update: true
Filter Conditions:
Billing status changes to Ceased AND
Contract is not empty AND
Contract.Billing status is Active
Script:
// Get GlideRecord Element of the Contract used on current Service Offering
var grContract = current.contract.getRefRecord();
// Check if there is any other non-Ceased Service Offering
// If there is none then Deactivate the Contract
var grServiceOfferings = new GlideRecord('service_offering');
grServiceOfferings.addQuery('contract', current.contract + '');
grServiceOfferings.addQuery('u_billing_status', '!=' ,'Ceased');
grServiceOfferings.addQuery('sys_id', '!=', current.sys_id + '');
grServiceOfferings.query();
if(!grServiceOfferings.hasNext()) {
grContract.u_billing_status = 'Inactive';
grContract.update();
}
This BR should do your job
Thanks,
Tanaji Patil
-- Please mark correct/helpful if it helps solving your issue.