- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2024 05:23 AM
Hi All.
I'm trying to update system set (sc_item_option)
I want to know that if you know something.
--------------------------------------------------
sample
-------------------------------------------------
// RITMNumber -> RITM + some number
// query table sc_item_option_mtom, get sc_item_option
var mtomGR = new GlideRecord('sc_item_option_mtom');
mtomGR.query();
var targetItemOptionSysID;
while (mtomGR.next()) {
if (mtomGR.getDisplayValue('request_item') == RITMNumber) {
targetItemOptionSysID = mtomGR.getValue('sc_item_option');
break;
}
}
// query table sc_item_option
var itemOptionGR = new GlideRecord('sc_item_option');
itemOptionGR.addQuery('sys_id', targetItemOptionSysID);
itemOptionGR.query();
while(itemOptionGR.next()){
if(itemOptionGR.getValue(value) == 'thisIsTarget'){
itemOptionGR.setValue('value', 'testValue');
itemOptionGR.update();
}
}
-------------------------------------------------
I'm not good at English.
You don't know what I said, Please ask me.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-17-2024 05:59 AM
Hi @Takumi_
Add a query condition, while you perform GlideRecord operation.
try the below code. this code will update the values where the values are "testValue" to test.
if you want to update any particular variables value to something then you have add a check condition in the GildeRecord of mtom table within the if loop under while loop.
var RITMNumber = 'RITM0010001'; // -> RITM + some number
// query table sc_item_option_mtom, get sc_item_option
var mtomGR = new GlideRecord('sc_item_option_mtom');
//mtomGR.addEncodedQuery("request_item.numberSTARTSWITH"+RITMNumber); // Always add a filter to out the unwanted response.
mtomGR.query();
var targetItemOptionSysID;
while (mtomGR.next()) {
if (mtomGR.getDisplayValue('request_item') == RITMNumber) {
targetItemOptionSysID = mtomGR.getValue('sc_item_option');
updateOptionValue(targetItemOptionSysID);
}
}
function updateOptionValue(sysid) {
// query table sc_item_option
var itemOptionGR = new GlideRecord('sc_item_option');
itemOptionGR.addQuery('sys_id', sysid);
itemOptionGR.query();
while (itemOptionGR.next()) {
if (itemOptionGR.getValue('value') == 'testValue') {
itemOptionGR.setValue('value', 'test');
itemOptionGR.update();
}
}
}
Cheers!!
Abhit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2024 01:42 AM
var RITMNumber = 'RITM0010001'; // -> RITM + some number
// query table sc_item_option_mtom, get sc_item_option
var mtomGR = new GlideRecord('sc_item_option_mtom');
//mtomGR.addEncodedQuery("request_item.numberSTARTSWITH"+RITMNumber); // Always add a filter to out the unwanted response.
mtomGR.query();
var targetItemOptionSysID;
while (mtomGR.next()) {
if (mtomGR.getDisplayValue('request_item') == RITMNumber) {
targetItemOptionSysID = mtomGR.getValue('sc_item_option');
updateOptionValue(targetItemOptionSysID);
}
}
function updateOptionValue(sysid) {
// query table sc_item_option
var itemOptionGR = new GlideRecord('sc_item_option');
itemOptionGR.addQuery('sys_id', sysid);
itemOptionGR.addQuery('item_option_new', 'hostname_1'); // hostname_1 is question.
itemOptionGR.query();
while (itemOptionGR.next()) {
if (itemOptionGR.getValue('value') == 'testValue') {
itemOptionGR.setValue('value', 'test');
itemOptionGR.update();
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2024 10:16 PM
Just small change on itemOptionGR.addQuery('item_option_new', 'hostname_1');
var RITMNumber = 'RITM0010001'; // -> RITM + some number
// query table sc_item_option_mtom, get sc_item_option
var mtomGR = new GlideRecord('sc_item_option_mtom');
//mtomGR.addEncodedQuery("request_item.numberSTARTSWITH"+RITMNumber); // Always add a filter to out the unwanted response.
mtomGR.query();
var targetItemOptionSysID;
while (mtomGR.next()) {
if (mtomGR.getDisplayValue('request_item') == RITMNumber) {
targetItemOptionSysID = mtomGR.getValue('sc_item_option');
updateOptionValue(targetItemOptionSysID);
}
}
function updateOptionValue(sysid) {
// query table sc_item_option
var itemOptionGR = new GlideRecord('sc_item_option');
itemOptionGR.addQuery('sys_id', sysid);
itemOptionGR.addQuery('item_option_new.name', 'hostname_1'); // hostname_1 is question.
itemOptionGR.query();
while (itemOptionGR.next()) {
if (itemOptionGR.getValue('value') == 'test123') {
itemOptionGR.setValue('value', 'test1234');
itemOptionGR.update();
}
}
}