- 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-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 02:02 AM
Thank you Abhit.
I can update system set.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2024 01:42 AM
Thank you for your answer.
It's almost perfect.
But I have one more question.
What I should do , if query question or name.
I added a query but it doesn't work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2024 03:47 AM
Hi @Takumi_
try the below line.
itemOptionGR.addQuery('item_option_new.question_text', 'hostname_1');
Abhit