Set form view through UI Action

scottangehr
Giga Guru

Good day team

I have a requirement to set the view of a form through a UI Action to a different table.

We have a UI Action on incident to create a new RITM for an equipment request.

The users have to set certain fields based on this view that was created (Equip_Request)

Is there a line of code to set the view in scripting

ie:  

function createRITM() {               //create the new Requested Item Record

  var newReq = new GlideRecord("sc_req_item");

newReq.setView("Equip_Request");

}

That's not working


Thanks

1 ACCEPTED SOLUTION

The redirect needs to include the view. Yours is simply going to the new request item record. Didn't you say you wanted to redirect to a specific view? That's where you'll have to build the URL including the sysparm_view= part I described above.


View solution in original post

7 REPLIES 7

Chuck Tomasi
Tera Patron

Something like:



function createRITM() {               //create the new Requested Item Record


  var newReq = new GlideRecord("sc_req_item");


        // set your fields here


        var id = newReq.insert();


        action.setRedirectURL('sc_req_item?sys_id=' + id + '&sysparm_view=YOURVIEWNAME');


}


Let me give you my whole code for this UI Action.


I tried adding your suggestion, editing my redirect...hasn't worked



createRITM();



function createRITM() {               //create the new Requested Item Record


var newReq = new GlideRecord("sc_req_item");


  newReq.initialize();


  newReq.u_caller.setDisplayValue(current.caller_id);


  newReq.assignment_group.setDisplayValue("Equipment Supply");


  newReq.cat_item.setDisplayValue("Req Item Task Creator");


  newReq.u_asset_serial=current.cmdb_ci;


  newReq.short_description=current.short_description;


  newReq.u_incident_id = current.sys_id.toString();


  newReq.watch_list=current.watch_list.getDisplayValue().toString();


  newReq.parent=current.sys_id;


  newReq.insert();



// update the record once, after the function call


current.state = 6; //setting it to Resolved state


current.close_code.setDisplayValue("Solved (Equipment Requested)");


current.close_notes=("Incident resolved, Requested Item "   + newReq.number + " created.");


current.comments=("Incident resolved, Requested Item "   + newReq.number + " created.");


  var mySysID = current.update();



  // now direct to the new Request


  gs.addInfoMessage("Incident resolved, Requested Item "   + newReq.number + " created.");


action.setRedirectURL(newReq);


action.setReturnURL(current);


  }


The redirect needs to include the view. Yours is simply going to the new request item record. Didn't you say you wanted to redirect to a specific view? That's where you'll have to build the URL including the sysparm_view= part I described above.


Thank you



I have changed the redirect to


action.setRedirectURL('sc_req_item?sys_id=' + newReq.insert + '&sysparm_view=Equip_Request');



It's now not taking me to the form on the sc_req_item, but reverts to the homepage so I can't tell if its setting the view of the form or not.