UI Action scripts to copy the current record

CCZMAX1
Mega Sage

Hi, I have created a client side UI action which copies the current record and opens a new record in classic view.

However, I have since discovered a neater way of doing it after seeing how it is done for the workspace and wondered if anyone could give any advise as to whether my original or shorter classic view version is better and would either cause any issues.

Thanks

Max

 

Original Version (classic)

 

function OnCopyReleaseClick() 
{ 
	var existingReleaseSysId = g_form.getUniqueValue();  //get the current record's sysid

	var grExistingRelease = new GlideRecord('rm_release'); //retrieve the current record to get the field values

	if (grExistingRelease.get(existingReleaseSysId)) //if the current records sysid set variables
	{
		var short_description = grExistingRelease.getValue('short_description');
               var description = grExistingRelease.getValue('description');
		var risk = grExistingRelease.getValue('u_risk');
		var cmdb_ci = grExistingRelease.getValue('cmdb_ci');
		var deployment_package = grExistingRelease.getValue('u_deployment_package');
		var assignment_group = grExistingRelease.getValue('assignment_group');
		var release_type = grExistingRelease.getValue('release_type');
	}

    var url = '/rm_release.do?sysparm_stack=rm_release.do&sys_id=-1&sysparm_query='; //base url

    url += 'short_description=' + encodeURIComponent(short_description) + '^description=' + encodeURIComponent(description) + '^u_risk=' + encodeURIComponent(risk)	+ '^cmdb_ci=' + encodeURIComponent(cmdb_ci) + '^u_deployment_package=' + encodeURIComponent(deployment_package) + '^assignment_group=' + encodeURIComponent(assignment_group) + '^release_type=' + encodeURIComponent(release_type);

    g_navigation.open(url); //go to the record opened with the value populated
}

 

Shorter Version (classic)

function Test() 
{ 
  var url = '/rm_release.do?sysparm_stack=rm_release.do&sys_id=-1&sysparm_query='; //base url 

  url += g_form.getValue('parent') + "^short_description=" + g_form.getValue('short_description') + "^description=" + g_form.getValue('description') + "^u_risk=" + g_form.getValue('u_risk') + "^cmdb_ci=" + g_form.getValue('cmdb_ci') + "^u_deployment_package=" + g_form.getValue('u_deployment_package') + "^release_type=" + g_form.getValue('release_type');

    g_navigation.open(url); //go to the record opened with the value populated
}

 

Workspace Version

function onClick(g_form) 
{   
g_aw.openRecord("rm_release", "-1", { query: "parent=" + g_form.getValue('parent') + "^short_description=" + g_form.getValue('short_description') + "^description=" + g_form.getValue('description') + "^u_risk=" + g_form.getValue('u_risk') + "^cmdb_ci=" + g_form.getValue('cmdb_ci') + "^u_deployment_package=" + g_form.getValue('u_deployment_package') + "^release_type=" + g_form.getValue('release_type')});

}

 

6 REPLIES 6

Thank you for your advice.

Max

Community Alums
Not applicable

Hi @CCZMAX1 ,

Welcome, happy to help you out with your problem. ðŸ˜€

 

Please mark my answer correct 

 

Thanks and Regards 

Sarthak