Setting a UI View using a UI Action

scottangehr
Giga Guru

Good day team

I'm having a conundrum with setting a view using a UI Action.  It worked previously and doesn't seem to want to now.  I have used the following to set the view when a UI Action is clicked:

   var link ="sc_request.do?sys_id="+sysID+"&sysparm_view=Account_Request";

When that didn't work, I searched the community and attempted to use this:

   task.set('sysparm_view', 'Account_Request');
   task.set('sysparm_view_forced','true');

Any help is appreciated.

Regards,
Scott

1 ACCEPTED SOLUTION

scottangehr
Giga Guru

Moved this up to after the tasksys.insert and it works

var link ="sc_request.do?sys_id="+task.sys_id+"&sysparm_view=account_request";
action.setRedirectURL(link);

View solution in original post

17 REPLIES 17

Can you share screenshots of the UI action (configuration and code)? That would help.

find_real_file.png

createRequest();

function createRequest() {
var notes = current.work_notes.getJournalEntry(-1);
var workNotes='';
var task = new GlideRecord("sc_request");
   task.short_description = current.short_description;
   //task.description = current.description;
	task.description = 'From Incident: ' +current.number + '\nCaller: ' + current.caller_id.getDisplayValue() + '\n' + current.description + '\n\n Comments:\n' + current.comments.getJournalEntry(-1) + '\n WorkNotes:\n' + current.work_notes.getJournalEntry(-1);
    task.assignment_group.setDisplayValue("Identity Access Management");
	task.state = 2;
   // task.assigned_to = current.assigned_to;
    task.priority = current.priority;
    task.parent = current.sys_id;
	task.requested_for = current.caller_id;
	task.opened_by = current.opened_by;
	task.contact_type = current.contact_type;
	task.due_date = current.due_date;
	task.location = current.location;
	task.phone = current.phone;
	task.impact = current.impact;
	task.urgency = current.urgency;
	if(notes != "")
	task.work_notes = workNotes;
   var taskSys = task.insert();

   //Insert relationship
   var rel = new GlideRecord('task_rel_task');
   rel.parent = current.sys_id;
   rel.child = taskSys;
   rel.type.setDisplayValue('Caused by::Causes');
   rel.insert();
	//copy Attachment
   GlideSysAttachment.copy('incident',current.sys_id,'sc_request',taskSys);
	
	//Close Current Incident
	var closeMSG = "This incident has been closed and a Request has been opened to resolve the problem: "  + task.number + '.';
	var user= gs.getUserID();
	current.state = 6;
	current.closed_at = gs.nowDateTime();
	current.closed_by = user;
	current.sys_updated_by = user;
	current.close_code = 'Defer to Request';
	current.close_notes = closeMSG;
	current.update();
	
	var link ="sc_request.do?sys_id="+sysID+"&sysparm_view=account_request"; //set the view when clicked
	
   gs.addInfoMessage(gs.getMessage("Request {0} created", task.number));
   action.setRedirectURL(task);
   action.setReturnURL(current);
   
}

scottangehr
Giga Guru

Moved this up to after the tasksys.insert and it works

var link ="sc_request.do?sys_id="+task.sys_id+"&sysparm_view=account_request";
action.setRedirectURL(link);