- 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-20-2017 03:31 AM
Hehehe
You answered your own question.
Raj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-20-2017 07:37 AM
Sometimes it helps to talk these things out i guess!!
I'm still having a little trouble with the script though. I'm using this below but it's working in random and sporadic ways which is not what you want from your script!
var serviceOrderID = current.getValue('contract');
var con = new GlideRecord('ast_contract');
if (con.get(serviceOrderID)){
var ser = new GlideRecord('service_offering');
ser.addQuery('contract', serviceOrderID);
ser.query();
while (ser.next()){
if (ser.u_billing_status == 'Ceased'){
con.u_billing_status = 'Inactive';
con.update();
}
else con.u_billing_status = 'Active';
con.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2017 02:54 AM
I'm really stuck on this. I'm convinced there's a problem with the if statement i've nested in the while loop but my 'copy and paste things i find on the community' brand of scripting is insufficient to the task of figuring out what that problem.
This is my script.
var serviceOrder = current.getValue('contract');
var con = new GlideRecord('ast_contract');
var ser = new GlideRecord('service_offering');
ser.addQuery('contract', serviceOrder);
ser.query();
if (con.get(serviceOrder)){
while (ser.next()){
if (ser.u_billing_status == 'Ceased'){
con.u_billing_status = 'Inactive';
}
else con.u_billing_status = 'Active';
}
con.update();
}
I'm testing on a contract with 2 service offerings. When both are active the contract is active, when both are ceased the contract is inactive. With both active and i change 1 from active to ceased, the contract stays active, with both active and i change the other from active to ceased the contract changes to inactive. Likewise when i change from both ceased to active, changes to one of the service offerings effects changes to the contract, changes to the other service offering do nothing.
So, only changes to one of the service offerings is affecting the status of the contract, i need the statement to say 'if all service offerings on the contract are ceased then mark the contract inactive, if not mark it active'. HOW?!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2017 03:17 AM
Hi Dave,
Try following script
var gr = new GlideRecord('service_offering');
gr.addQuery('contract', current.sys_id);
gr.addQuesry('u_billing_status','!=' ,'Ceased')
gr.query();
if (gr.hasNext())
{
current.u_billing_status = 'Active';
gs.addErrorMessage("Active service offerings should be ceased before marking the contract inactive");
current.setAbortAction(true);
gs.setRedirect(current);
}
else
{
current.u_billing_status = 'Inactive';
}
You need to write this BR on Contract table.
Raj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2017 03:32 AM
Thanks Raj but then i'm back to the quandry of how to trigger that business rule when the billing status changes on a service offering.
Perhaps i could use hasNext() as below, i just don't know how to say 'else set the contract to inactive'
var serviceOrder = current.getValue('contract');
var con = new GlideRecord('ast_contract');
var ser = new GlideRecord('service_offering');
ser.addQuery('contract', serviceOrder);
ser.addQuery('u_billing_status', 'Active');
ser.query();
if (con.get(serviceOrder)){
while (ser.hasNext()){
con.u_billing_status = 'Active';
}