Using Client script onchange
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2022 03:57 AM
Hi,
I need take in relation twoo table cmdb_ci_business_app and cmdb_ci_vmware_instance by a client script creation on change item "IT application owner" on table cmdb_ci_business_app.
everytime change value about Item "IT application owner" I need update the item owner with same value on table cmdb_ci_vmware_instance for each recods with cmdb_ci_business_app.name=mdb_ci_vmware_instance.application
I develope this code in first istance but dont work:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var cat = new GlideRecord("cmdb_ci_business_app");
var vm_rec = new GlideRecord("cmdb_ci_vmware_instance");
vm_rec.query();
cat.query();
while (cat.next()) {
while (vm_rec.next()) {
if (vm_rec.u_application == cat.name || cat.it_application_owner==newValue) {
vm_rec.u_owner=newValue;
}
vm_rec.update();
}
cat.update();
}
}
Could you supporto me?
thanks a lot
Genny
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2022 08:22 PM
Hi Genny,
>why I can't use clien script onchange?
Simply put, there's no .update() method in Client side GlideRecord().
Update is used to update a record in a database. Database resides on a server. That's why update must be done on a server-side and not on client-side.
FYI. .update() documentation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2022 08:48 PM
Hi again,
>everytime change value about Item "IT application owner" I need update the item owner with same value on table cmdb_ci_vmware_instance for each recods with cmdb_ci_business_app.name=mdb_ci_vmware_instance.application
To satisfy this condition, it's better to create a business rule because business rule is able to execute every time a field value changes on a table. That is, if a user changes value of "IT Applicaiton owner" from the list view, business rule will also execute and update the cmdb_ci_vmware record.
Following steps will create a business rule.
- From Application Navigator, go to "System Definition" > "Business Rules".
- Click the "New" button
- Set "Table" to "Business Application" and check "Insert" and "Update".
Set Filter Condition to "Name", "changes" - Check "Advanced" checkbox and select "Advanced" tab and enter script to update cmdb_ci_vmware_instance record.
(function executeRule(current, previous /*null when async*/) { var grVm = new GlideRecord("cmdb_ci_vmware_instance"); grVm.addActiveQuery(); grVm.addQuery('u_application', current.name); grVm.query(); if (grVm.next()) { grVm.u_owner = current.it_application_owner; grVm.update(); } })(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2022 06:43 AM
