- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2023 07:46 AM
Hi Team,
i have a string field called 'address_attribute' which is populated from azure Integration with value like (street address, State, City, zip, Office Address1, Office Address2)
i need to set the values of fields (Street address, state,city,zip, office address, office address 1) from the address_attribute field.
in above screenshot, i want to set the value of fields state and office address to their respecctive value.
Thank you,
Hari Kishan.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2023 07:57 AM
Hi,
You can do it by split
var array = current.address_attribute.split(",");// If server script
var array = g_form.getValue ("address_attribute").split(",");// If client script
var street =array[0];
var zip =array[3];....
//Then you have just to update your field by current.zip// or g_form.setValue it depends if your are on client or server side
I hope it's helpful
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2023 07:57 AM
Hi,
You can do it by split
var array = current.address_attribute.split(",");// If server script
var array = g_form.getValue ("address_attribute").split(",");// If client script
var street =array[0];
var zip =array[3];....
//Then you have just to update your field by current.zip// or g_form.setValue it depends if your are on client or server side
I hope it's helpful
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2023 08:07 AM
To set the values of fields (Street address, state, city, zip, office address, office address 1) from the 'address_attribute' field, you can create a Business Rule that triggers on insert or update.
Here's how you can do that:
- Create a new Business Rule:
a. In your ServiceNow instance, navigate to System Definition > Business Rules.
b. Click on "New" to create a new Business Rule.
d. Set the "When to run" options as follows:
- Check the "When" checkboxes for "before" and "insert" as well as "update."
- Check the "Order" checkbox and set the value to "100."
- In the "Advanced" tab, paste the following script:
(function executeRule(current, previous /*null when async*/) { var addressAttribute = current.address_attribute.toString(); // Split the address_attribute string into an array var addressComponents = addressAttribute.split(','); // Assuming the address components are ordered as: Street, State, City, Zip, Office Address1, Office Address2 current.street_address = addressComponents[0].trim(); current.state = addressComponents[1].trim(); current.city = addressComponents[2].trim(); current.zip = addressComponents[3].trim(); current.office_address = addressComponents[4].trim(); current.office_address_1 = addressComponents[5].trim(); })(current, previous);
- Click on "Submit" to create the Business Rule.
This Business Rule will parse the 'address_attribute' field and set the values of the Street address, state, city, zip, office address, and office address 1 fields accordingly.
Please note that you might need to adjust the script according to the actual field names in your instance if they differ from the standard field names. Also, ensure the address components in the 'address_attribute' field are ordered as shown in the script, or modify the script to accommodate the order in which they appear.