How to make use of System property in UI Action?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2022 10:04 PM
I want to create a copy request through the system property fields.(additional_comments,state).Whenever i create a request i am getting additional comments value as blank.Please guide me in this.
function showConfirmationPopup() {
var answer = confirm("Are you sure you want to make a copy of this request?");
if (answer == true) {
gsftSubmit(null, g_form.getFormElement(), 'copy_req'); //MUST call the 'Action name' set in this UI Action
} else {
return false;
}
}
if (typeof window == 'undefined')
openCopy();
function openCopy() {
var curSysID = current.sys_id;
var curNum = current.number;
var cpy = new GlideRecord("sc_req_item");
var value = gs.getProperty("com.snc.request.copy.rl.task_ci.attributes");
cpy.additional_comment=value.additional_comment;
cpy.parent = curSysID;// var abc = [];
var sysID = cpy.insert();
cpy.work_notes = "This incident was created from a copy of incident " + curNum + " by user " + gs.getUserDisplayName() + " See the list of incidents created by the same caller below for more information.";
cpy.update();
current.work_notes = "This incident was used to as a copy to create " + cpy.number + ". See the list of incidents created by the same caller below for more information.";
var mySysID = current.update();
action.setRedirectURL(cpy);
action.setReturnURL(current);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2022 10:08 PM
Hi,
YOu need to loop in through the property. Please use the modified code below:
function showConfirmationPopup() {
var answer = confirm("Are you sure you want to make a copy of this request?");
if (answer == true) {
gsftSubmit(null, g_form.getFormElement(), 'copy_req'); //MUST call the 'Action name' set in this UI Action
} else {
return false;
}
}
if (typeof window == 'undefined')
openCopy();
function openCopy() {
var curSysID = current.sys_id;
var curNum = current.number;
var cpy = new GlideRecord("sc_req_item");
var value = gs.getProperty("com.snc.request.copy.rl.task_ci.attributes");
for(var i =0;i<value.length;i++){
cpy.additional_comment=value[i].additional_comment;
}
cpy.parent = curSysID;// var abc = [];
var sysID = cpy.insert();
cpy.work_notes = "This incident was created from a copy of incident " + curNum + " by user " + gs.getUserDisplayName() + " See the list of incidents created by the same caller below for more information.";
cpy.update();
current.work_notes = "This incident was used to as a copy to create " + cpy.number + ". See the list of incidents created by the same caller below for more information.";
var mySysID = current.update();
action.setRedirectURL(cpy);
action.setReturnURL(current);
}
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2022 10:16 PM
Also, I see an issue with your code where you are not initializing it when creating record. So I have modified your code. Please test it with below code:
function showConfirmationPopup() {
var answer = confirm("Are you sure you want to make a copy of this request?");
if (answer == true) {
gsftSubmit(null, g_form.getFormElement(), 'copy_req'); //MUST call the 'Action name' set in this UI Action
} else {
return false;
}
}
if (typeof window == 'undefined')
openCopy();
function openCopy() {
var curSysID = current.sys_id;
var curNum = current.number;
var cpy = new GlideRecord("sc_req_item");
cpy.initialize();
var value = gs.getProperty("com.snc.request.copy.rl.task_ci.attributes");
for (var i = 0; i < value.length; i++) {
cpy.additional_comment = value[i].additional_comment;
}
cpy.parent = curSysID; // var abc = [];
var success = cpy.insert();
if (success) {
current.work_notes = "This incident was used to as a copy to create " + cpy.number + ". See the list of incidents created by the same caller below for more information.";
current.update();
cpy.work_notes = "This incident was created from a copy of incident " + curNum + " by user " + gs.getUserDisplayName() + " See the list of incidents created by the same caller below for more information.";
cpy.update();
action.setRedirectURL(cpy);
}
}
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2022 10:42 PM
Thankyou!.but not able to create additional_comment with same name.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2022 12:10 AM
Hi,
Have reviewed your script and found it was incorrect. Since you are planning to use System properties and fetch the value from Property for different Field, please follow the approach to store value as a JSON object rather than string , which I feel is a much better and structure way to do it.
Update your System property as below for example, you can add nay number of name pairs as shown below:
{"additionalComment": "This is copied",
"state":"3"
}
Similarly add other combinations as name and then value in quotes:
Now you need to update your UI Action code as well, please use the below modified code and have tested it it is working correctly:
function showConfirmationPopup() {
var answer = confirm("Are you sure you want to make a copy of this request?");
if (answer == true) {
gsftSubmit(null, g_form.getFormElement(), 'copy_req'); //MUST call the 'Action name' set in this UI Action
} else {
return false;
}
}
if (typeof window == 'undefined')
openCopy();
function openCopy() {
var value = gs.getProperty("com.snc.request.copy.rl.task_ci.attributes");
var getVal = JSON.parse(value);
var gr = new GlideRecord('sc_req_item');
gr.initialize();
gr.parent = current.sys_id;
gr.comments = getVal.additionalComment;
gr.state = getVal.state;
var success = gr.insert();
if (success) {
gr.work_notes = "This Request was used to as a copy to create " + gr.number + ". See the list of incidents created by the same caller below for more information.";
gr.update();
action.setRedirectURL(gr);
}
}
This is working correctly in my PDI. You can set any other field you want while creating new records.
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke