- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2021 09:27 AM
Hi All
I have a requirement that says whenever the "Service Type" field on the service offering table(child table) is inserted or updated.
on the parent table called "Business Service " the "Service Type" field should be updated with the same as the child table's "service type" value
Can someone provide me a solution..???
Thanks
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2021 04:01 AM
Dot walk and update doesn't work, you have to GlideRecord to parent record and update it.
(function executeRule(current, previous /*null when async*/ ) {
var servicetype = current.getValue('u_service_type');
if (JSUtil.notNil(current.parent)){
var gr = new GlideREcord('<parent table>');/add the table name here
gr.addQuery('sys_id',current.parent )
gr.query();
if(gr.next())
{
gr.u_service_type = servicetype;
gr.update();
}
})(current, previous);
The condition of the BR should be that current.parent is not empty AND current.u_service_type Changes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-29-2021 09:34 AM
not knowing the names of tables and fields in question its difficult to write code. Plus you wont learn
So Id suggest you write the code and then, if it doesn't work, add here and you will get the help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2021 02:24 AM
(function executeRule(current, previous /*null when async*/ ) {
var servicetype = current.getValue('u_service_type'); //'service type' field on serviceoffering table
var Par = current.getValue('parent'); //'parent' field on serviceoffering table
var gr = new GlideRecord('cmdb_ci_service'); //'cmdb_ci_service' is parent table
gr.addQuery('sys_id', 'Par');
gr.query();
while (gr.next()) {
g_form.setValue(gr.u_service_type,servicetype);
}
})(current, previous);
This is the script I have tried
service offering(service_offering) table has service type(u_service_type) field and also
Business service(cmdb_ci_service) table also has service type(u_service_type).
So whenever the service type in the service offering table is inserted or updated it should update the same in the business service table service type.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2021 02:43 AM
Try this
(function executeRule(current, previous /*null when async*/ ) {
var servicetype = current.getValue('u_service_type'); //'service type' field on serviceoffering table
var Par = current.getValue('parent'); //'parent' field on serviceoffering table
var gr = new GlideRecord('cmdb_ci_service'); //'cmdb_ci_service' is parent table
gr.addQuery('sys_id', Par);
gr.query();
while (gr.next()) {
gr.u_service_type = servicetype;
gr.update();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2021 08:39 AM
Sir, I tried this but whenever service type on service offering changes the immediate parent that is on the business service the service type changes but grand parent and grand grand parent record are not changing
So any changes to the existing script to be done or another BR on the Business service table to be written.