Server side Code – Assignment

 

 

Test (Table)

Auto Number
Short Description
User (reference to sys_user)
Incident (reference to incident)

After Creating a record in test table, Incident should get created with the following values

Test Table                               Incident Table

Short Description ——— short Description
User ———————- Assigned to

After Creating incident, please update the test record with the incident number in the Incident reference value.

For example

Test (Table)

Auto Number:Test001
short Description: Test short description
User: Pavan Patil
Incident: INC001

Incident record should be

AutoNumber: INC001
short Description: Test short description
Assinged to: Pavan Patil

If you update the user field value of Test Table record , it should update the incident assinged to field of the same incident which is on the form.

After Update

Test (Table)

Auto Number:Test001
short Description: Test short description
User: Meghana Patil
Incident: INC001

Incident Record should be

Auto Number: INC001
short Description: Test short description
Assigned to: Meghana Patil

………………………………………………………………………………………………………………………….

Please refer the Test Table Below

Script Include:

var Test17 = Class.create();
Test17.prototype = {
initialize: function() {
},

insertSD: function(sd,user){

var gr = new GlideRecord(“incident”);
gr.initialize();
gr.short_description=sd;
gr.assigned_to=user;
var ch = gr.insert();

return ch;
},

updateUser: function(inc,user){

var ch = “”;
var gr = new GlideRecord(“incident”);
gs.addInfoMessage(gs.getMessage(“INC = “+inc));
gr.addEncodedQuery(“sys_id=”+inc);
gr.query();
if(gr.next()){
gr.assigned_to=user;
ch = gr.update();
}
return ch;
},

type: ‘Test17’
};

 

For Requirement below

 

After Creating a record in test table, Incident should get created with the following values

Test Table                               Incident Table

Short Description ——— short Description
User ———————- Assigned to

After Creating incident, please update the test record with the incident number in the Incident reference value.

 

We need to write the Business rule on TEST table i.e. after Insert and need to call the script include function  “insertSD”

(After Insert)

(function executeRule(current, previous /*null when async*/) {

var f = new Test17();
var sid = f.insertSD(current.u_short_description,current.u_user);

gs.addInfoMessage(gs.getMessage(“Done!”)+sid);

current.u_incident=sid;
current.update();

})(current, previous);

Requirement 2:

If you update the user field value of Test Table record , it should update the incident assigned to field of the same incident which is on the form.

For this we need to write second business rule on TEST table i.e. After update and need to call the function “updateUser” from script include

(After Update)

(function executeRule(current, previous /*null when async*/) {

var f = new Test17();
var p = f.updateUser(current.u_incident,current.u_user);

gs.addInfoMessage(gs.getMessage(“Check: “+p));

})(current, previous);

About the author

Leave a Reply