Triggering a Business Rule when an object on a related list is changed

Dubz
Mega Sage

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

1 ACCEPTED SOLUTION

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


View solution in original post

13 REPLIES 13

rajmasurkar
Giga Guru

Hi David,



Use while instead of if




Raj


Thanks Raj, that was simple!



Any idea how i can trigger this rule without having to update the contract form? At the moment i'm thinking i might have to set up another rule on the service offering to update some field on the contract when the billing status changes which i would like to avoid if possible.


Hi Dave,



Can you explain me your exact requirement please?



Raj


Hi Raj,



Service offerings are related to Contracts so on the Contract form there is a related list with all the service offerings associated with that contract. On the service offering from there is a reference field linking back to the contract.



I need the contract to be marked as Inactive when all associated service offerings are marked as Ceased. When the billing status on the service offering form is changed to Ceased there is no change made to the Contract form so my on insert and update business rule is not triggering.



What i need is for this rule to be triggered every time the billing status of an associated service offering changes.



I'm thinking about it now and realising i've probably come at this rule backwards, i think i needed to create a business rule on the service offering form to trigger whenever the billing status changes and then glide into the contract form and run the relevant check on all associated service offerings...