- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2023 01:05 AM - edited 11-23-2023 01:07 AM
Hello All,
Is it possible to copy a variable via scripting?
I have created UI page which is taking values from respective table
Please see below popup screenshot for reference.
I need to create copy of selected above variable to below catalog item variable related list
For instance, I would like to copy a variable selected on ui page and make a new variable (copy of selected variable).
Instead of manually creating a new variable from catalog item page, is it possible to existing variable and simply rename it?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2023 09:36 PM
Below Are few notes :
- For variable : We can not populate existing variable selected on new catalog item form, So as per try and error we are able to insert new duplicate variable and we have tried this for Reference variable type.
- Going forward there will be more variables with the same name present on the variable table and users may get confused which variable needs to be selected.
- There are more variable types,so for example if user select - Select Box type of variable then there will be choices related to it,so again if we want to copy selected variable then we have to create duplicate choices for the same variable,And this may repeat for all variables.
- Next point every time the user will select the variable ,we need to check the type and then according to the type we need to write the script,But we are not sure that this will work.
- This select location has different respective Question choices associated with it.so How will the user will get to know which select_location should be selected?
- We would suggest not to create duplicate variables by using existing variable’s data instead users can create new variables manually as per user’s requirement once a software model is published to catalog items as its OOB functionality.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2023 05:20 PM
Hi, drilling into a variable aka 'item_option_new' record in a PDI.
I see a 'copy button top right had side of form and also have 'Insert and stay' option in the UI menu
Based on the need to rename, I would open a variable, make required changes IE rename, change the referenced Catalog item, and then try using 'Insert and stay' from the UI menu.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2023 11:20 PM
@Tony Chatfield1
I am aware of insert and stay option,But we are doing it through script in UI Page.
Till now I have done below code
Ui page : Processing script :
var oldVariable = new GlideRecord('item_option_new');
oldVariable.addQuery('sys_id', variable);
oldVariable.query();
if (oldVariable.next()) {
gs.info("Oldvariable record found ");
var newVarGR = new GlideRecord('item_option_new');
gs.info("variable initialized ");
var nameVal = oldVariable.getValue('name');
newVarGR.initialize();
newVarGR.setValue('name', oldVariable.getValue('name') + '_01');
var newName = newVarGR.getValue('name');
var result = nameVal.indexOf(newName);
gs.info('result '+result);
newVarGR.setValue('type', oldVariable.getValue('type'));
newVarGR.setValue('question_text', oldVariable.getValue('question_text'));
newVarGR.setValue('cat_item', grCMDB.product_catalog_item);
newVarGR.setValue('reference', oldVariable.getValue('reference'));
newVarGR.setValue('use_reference_qualifier', oldVariable.getValue('use_reference_qualifier'));
newVarGR.insert();
gs.info("variable inserted");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2023 09:36 PM
Below Are few notes :
- For variable : We can not populate existing variable selected on new catalog item form, So as per try and error we are able to insert new duplicate variable and we have tried this for Reference variable type.
- Going forward there will be more variables with the same name present on the variable table and users may get confused which variable needs to be selected.
- There are more variable types,so for example if user select - Select Box type of variable then there will be choices related to it,so again if we want to copy selected variable then we have to create duplicate choices for the same variable,And this may repeat for all variables.
- Next point every time the user will select the variable ,we need to check the type and then according to the type we need to write the script,But we are not sure that this will work.
- This select location has different respective Question choices associated with it.so How will the user will get to know which select_location should be selected?
- We would suggest not to create duplicate variables by using existing variable’s data instead users can create new variables manually as per user’s requirement once a software model is published to catalog items as its OOB functionality.
Thanks!