- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2017 03:11 PM
I'm just ran into the new "change model" that I think came with Helsinki.
Before you could create a change_request like this:
var newChg = new GlideRecord('change_request');
newChg.newRecord();
newChg.comments = 'Testing';
newChg.type = 'emergency';
newChg.insert();
And it still works, but.. If you look at the UI Action on incident table called "Create Normal Change".
It's code look like this now:
var changeRequest = ChangeRequest.newNormal();
changeRequest.setValue("short_description", current.short_description);
changeRequest.setValue("description", current.description);
changeRequest.setValue("cmdb_ci", current.cmdb_ci);
changeRequest.setValue("priority", current.priority);
changeRequest.setValue("sys_domain", current.sys_domain);
changeRequest.setValue("company", current.company);
changeRequest.insert();
And problem here is if how do I add a comment or work notes with this code..
changeRequest.setValue("comment", 'Testing'); doesnt work.
Any ideas?
//Göran
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2017 01:24 PM
This is how I solved it.
Bare with my explanation, I'm pretty sure I ain't using all the correct words for the stuff below, since I'm a self learned JavaScript kiddie.
There is a script include called ChangeRequestSNC which is the one SN has created with all nice features. But this is read only so we don't mess with it.
They have then created ChangeRequest which extends from the ChangeRquestSNC class and lets us mortals to add functionality for this "class".
So I added my own functionality here called setComment.
That makes the script include look like this:
var ChangeRequest = Class.create();
ChangeRequest.NORMAL = "normal";
ChangeRequest.STANDARD = "standard";
ChangeRequest.EMERGENCY = "emergency";
ChangeRequest.CHANGE_REQUEST = "change_request";
ChangeRequest.prototype = Object.extendsObject(ChangeRequestSNC, {
setComment: function(value) {
this._gr.comments = value;
},
type: "ChangeRequest"
});
ChangeRequest.newNormal = ChangeRequestSNC.newNormal;
ChangeRequest.newStandard = ChangeRequestSNC.newStandard;
ChangeRequest.newEmergency = ChangeRequestSNC.newEmergency;
ChangeRequest.newChange = ChangeRequestSNC.newChange;
Now I just add this line in my UI Action and it works like a charm:
changeRequest.setComment("My comment");
And the whole UI Action looks like this:
(function(current, previous, gs, action) {
var changeRequest = ChangeRequest.newNormal();
changeRequest.setValue("short_description", current.short_description);
changeRequest.setValue("description", current.description);
changeRequest.setValue("cmdb_ci", current.cmdb_ci);
changeRequest.setValue("priority", current.priority);
changeRequest.setValue("sys_domain", current.sys_domain);
changeRequest.setValue("company", current.company);
changeRequest.setValue("comments", 'testing');
changeRequest.setComment("My comment");
changeRequest.insert();
current.rfc = changeRequest.getGlideRecord().getUniqueValue();
current.update();
//Copy Attachments
//Check if current has attachments
var checkAtt = new GlideRecord('sys_attachment');
checkAtt.addQuery('table_sys_id',current.getUniqueValue());
checkAtt.query();
//If there is attachment, copy it to the change
if (checkAtt.hasNext()){
GlideSysAttachment.copy('incident', current.getUniqueValue(), 'change_request', current.rfc);
}
//End copy attachment
gs.addInfoMessage("Change " + changeRequest.getValue("number") + " created");
action.setRedirectURL(changeRequest.getGlideRecord());
action.setReturnURL(current);
})(current, previous, gs, action);
Hope this will help more people than me with this question and give ideas of what else to do.
//Göran
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2017 09:32 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2017 01:24 PM
This is how I solved it.
Bare with my explanation, I'm pretty sure I ain't using all the correct words for the stuff below, since I'm a self learned JavaScript kiddie.
There is a script include called ChangeRequestSNC which is the one SN has created with all nice features. But this is read only so we don't mess with it.
They have then created ChangeRequest which extends from the ChangeRquestSNC class and lets us mortals to add functionality for this "class".
So I added my own functionality here called setComment.
That makes the script include look like this:
var ChangeRequest = Class.create();
ChangeRequest.NORMAL = "normal";
ChangeRequest.STANDARD = "standard";
ChangeRequest.EMERGENCY = "emergency";
ChangeRequest.CHANGE_REQUEST = "change_request";
ChangeRequest.prototype = Object.extendsObject(ChangeRequestSNC, {
setComment: function(value) {
this._gr.comments = value;
},
type: "ChangeRequest"
});
ChangeRequest.newNormal = ChangeRequestSNC.newNormal;
ChangeRequest.newStandard = ChangeRequestSNC.newStandard;
ChangeRequest.newEmergency = ChangeRequestSNC.newEmergency;
ChangeRequest.newChange = ChangeRequestSNC.newChange;
Now I just add this line in my UI Action and it works like a charm:
changeRequest.setComment("My comment");
And the whole UI Action looks like this:
(function(current, previous, gs, action) {
var changeRequest = ChangeRequest.newNormal();
changeRequest.setValue("short_description", current.short_description);
changeRequest.setValue("description", current.description);
changeRequest.setValue("cmdb_ci", current.cmdb_ci);
changeRequest.setValue("priority", current.priority);
changeRequest.setValue("sys_domain", current.sys_domain);
changeRequest.setValue("company", current.company);
changeRequest.setValue("comments", 'testing');
changeRequest.setComment("My comment");
changeRequest.insert();
current.rfc = changeRequest.getGlideRecord().getUniqueValue();
current.update();
//Copy Attachments
//Check if current has attachments
var checkAtt = new GlideRecord('sys_attachment');
checkAtt.addQuery('table_sys_id',current.getUniqueValue());
checkAtt.query();
//If there is attachment, copy it to the change
if (checkAtt.hasNext()){
GlideSysAttachment.copy('incident', current.getUniqueValue(), 'change_request', current.rfc);
}
//End copy attachment
gs.addInfoMessage("Change " + changeRequest.getValue("number") + " created");
action.setRedirectURL(changeRequest.getGlideRecord());
action.setReturnURL(current);
})(current, previous, gs, action);
Hope this will help more people than me with this question and give ideas of what else to do.
//Göran