Confusion between Insert and update in Business rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi Everyone,
I have before business rule with insert and update checkbox as true. and this BR is for custom table which is for Supply chain order table to order parts for agents from mobile. Currently the condition on filter for BR is:
| Street | changes | OR |
| city | changes | OR |
| state | changes | OR |
| postal code | changes | OR |
Current Script: current script is for whenever any changes happen to street, city, state, postal code.Current logic is ofcourse needed for whenever updates happen but want to add logic for insert also:
(function executeRule(current, previous /*null when async*/ ) {
gs.log('BR called');
var TSR = current.u_user;
var XeroxUtils = new XeroxLoqateIntegrationUtils();
var error = 'Enter a valid address';
var cmnGR = new GlideRecord('cmn_location');
cmnGR.addQuery('street', current.getValue('u_street'));
cmnGR.addQuery('country', current.getValue('u_country'));
cmnGR.addQuery('state', current.getValue('u_state_province'));
cmnGR.addQuery('zip', current.getValue('u_postal_code'));
var city;
cmnGR.query();
while (cmnGR.next()) {
city = cmnGR.getValue('city');
}
var data = {
"STREET": current.getValue('u_street'),
"COUNTRY": current.getValue('u_country'),
"STATE": current.getValue('u_state_province'),
"CITY": (current.getValue('u_city') ? current.getValue('u_city') : city),
"POSTALCODE": current.getValue('u_postal_code')
};
//gs.info('IK: Data object: ' + JSON.stringify(data));
// Location validation
//var responseArray = XeroxUtils.getLocationfromLoqateAPI(data, true);
var locationID = XeroxUtils.getLocation(data, true, "supply_chain_order");
//gs.info('IK: Location ID: ' +locationID);
if (!gs.nil(locationID)) {
current.location = locationID;
current.u_location_address = locationID;
var location = new GlideRecord("cmn_location");
var stkRoom = new GlideRecord("alm_stockroom");
if (gs.hasRole('wm_ext_agent')) { //contractors using a diffrent stockroom type
stkRoom.addQuery("assignment_group", current.assignment_group);
} else {
stkRoom.addQuery("type", "e2aa2b3f3763100044e0bfc8bcbe5dde");
stkRoom.addQuery("manager", TSR);
}
stkRoom.query();
// Assign value of service budget center
if (stkRoom.next()) {
var service_budget_center = stkRoom.u_service_budget_center;
location.get(locationID);
location.u_service_budget_center = stkRoom.u_service_budget_center;
//location.u_service_budget_center_stockroom = stkRoom.sys_id + '';
if (gs.hasRole('wm_ext_agent') && current.u_new_location_name != '') {
location.name = current.u_new_location_name;
location.managed_by_group = current.assignment_group;
}
}
location.update();
} else {
gs.addErrorMessage('Please select a valid Location or enter a new location using Street, City, Country, Postal code');
current.setAbortAction(true);
try {
action.setRedirectURL(current);
} catch (error) {
gs.log("IK: aborting location update in BR 'XRX Validate Location using Loqate'");
}
}
})(current, previous);Now we want to make changes to this BR whenever new part is ordered from mobile, then it should check following conditions, if either of the conditions meet then we don't see error message:
conditions:
1. Ship to WOT location is true (Ship to WOT location is toggle button on mobile screen which is UI parameter which linked to data parameter (wot_location)) OR
2. A saved address is selected from the location dropdown (u_location_address) OR
3. A new address has been entered and is fully populated (all required fields are filled)
If one of the conditions is not met, display the error message" Please provide a complete address for shipping."
If the condition is met, then store the Supply Chain Order Record.
Note: These fields should be required if "Ship to WOT" is false and Location dropdown is null, along with existing required fills.
STREET, CITY, STATE, POSTAL_CODE, COUNTRY
How can I make changes to my existing BR to accommodate new enhancement. I am bit confused
Thanks in advance