UI Action to show pop up with values of a table

Alon Grod
Tera Expert

I have the field u_jira_project on the incident table of type Reference to u_jira_project table. I need to create a form button called 'Create Jira'. When the user click on this button, he needs to see a pop up with all the projects from u_jira_project table divded into two columns: u_project_name, u_project key. After the user chose a project, the value of the project that he chose need to be populated inside u_jira_project field on the incident table. How can I achieve that?

3 ACCEPTED SOLUTIONS

@Alon Grod 

 

Their is one more error: make it name,key

 

var $j = jQuery.noConflict();
var ga = new GlideAjax('ShowJiraProject');
ga.addParam('sysparm_name', 'getProjects');
ga.getXML(parseResponse);

function parseResponse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
var str = "<div><table class='table' id='tableData'><tr><th>Name</th><th>Key</th></tr>";
answer = JSON.parse(answer);
for (var i = 0; i < answer.length; i++) {
str = str + '<tr id="tableRow"><td>' + answer[i].name +'</td><td>' + answer[i].key + '</td></tr>';
}
$j('#iframee').append(str);
}

  

View solution in original post

@Alon Grod,

 

There are a lot many tasks in this, will try to help you as I get time daily!

I am also stuck somewhere that has to be completed before this week ends!

 

I hope you understand 🙂

View solution in original post

Mathieu Lepoutr
Mega Guru

Hi

You can achieve this functionality by creating an ui-action on the incident table, which opens a dialog window with a list of projects from the u_jira_project table. Once the user selects a project, a script can set the value of the u_jira_project field on the incident table to the selected project's sys_id.


Please have a look at Exalate integration software. It enables you to synchronize data between the two systems, including incidents and projects, automating the transfer and ensuring they remain in sync. 

View solution in original post

33 REPLIES 33

Rahul Kumar17
Tera Guru

Hi,

To achieve this functionality, you can follow the below steps:

  1. Create a new UI action by navigating to "System Definition" > "UI Actions" in the application navigator.
  2. Click on the "New" button to create a new UI action record.
  3. In the "UI Action" form, give a name to the action (e.g. "Create Jira").
  4. Set the table to "incident" table.
  5. Set the type to "Action".
  6. In the "Action name" field, enter the name you want to display on the form button (e.g. "Create Jira").
  7. In the "Onclick" field, enter the following code:

function createJira() {
var dlg = new GlideModal('jira_project_modal');
dlg.setTitle('Select a project');
dlg.setWidth(600);
dlg.render();
}

createJira();

  1. Save the UI action record.
  2. Create a new UI page by navigating to "System UI" > "UI Pages" in the application navigator.
  3. Click on the "New" button to create a new UI page record.
  4. In the "UI Page" form, give a name to the page (e.g. "Select Jira Project").
  5. Set the "Page" field to "Form".
  6. In the "Table" field, select "u_jira_project".
  7. In the "Type" field, select "List".
  8. In the "View" field, select "Default".
  9. In the "Template" field, select "Bootstrap Modal".
  10. Click the "Submit" button to create the UI page record.
  11. In the newly created UI page record, click on the "Client Scripts" related list and add a new client script.
  12. In the client script, enter the following code:

function selectJiraProject(sys_id, project_name, project_key) {
var ga = new GlideAjax('incidentUtils');
ga.addParam('sysparm_name', 'setJiraProject');
ga.addParam('sysparm_sys_id', sys_id);
ga.addParam('sysparm_project_name', project_name);
ga.addParam('sysparm_project_key', project_key);
ga.getXML(function(response) {
if (response.responseXML.documentElement.getAttribute("answer") == "success") {
g_form.setValue('u_jira_project', sys_id);
}
});
GlideModal.dismiss('jira_project_modal');
}

  1. Create a new script include by navigating to "System Definition" > "Script Includes" in the application navigator.
  2. Click on the "New" button to create a new script include record.
  3. In the "Script Include" form, give a name to the script include (e.g. "Incident Utils").
  4. In the "Script" field, enter the following code:

var IncidentUtils = Class.create();
IncidentUtils.prototype = {
initialize: function() {
},
setJiraProject: function() {
var sys_id = this.getParameter('sysparm_sys_id');
var project_name = this.getParameter('sysparm_project_name');
var project_key = this.getParameter('sysparm_project_key');
var gr = new GlideRecord('u_jira_project');
if (gr.get(sys_id)) {
gr.u_project_name = project_name;
gr.u_project_key = project_key;
gr.update();
return 'success';
} else {
return 'error';
}
},
type: 'IncidentUtils'
};

 

Thanks,

Rahul Kumar

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar

@Rahul Kumar17 if i wanted to use CHAT gpt i would have done that by myself

Hi,

 

Create UI Action

 

var ga = new GlideAjax('GetJiraProjects');
ga.addParam('sysparm_name', 'getJiraProjects');
ga.getXML(parseResponse);

function parseResponse(response) {
  var answer = response.responseXML.documentElement.getAttribute("answer");
  var projects = JSON.parse(answer);
  
  var projectList = "";
  for (var i = 0; i < projects.length; i++) {
    var project = projects[i];
    projectList += "<option value='" + project.sys_id + "'>" + project.u_project_name + " (" + project.u_project_key + ")" + "</option>";
  }

  var dialog = new GlideModal('select_jira_project');
  dialog.setTitle('Select Jira Project');
  dialog.setWidth('40%');
  dialog.setPreference('projects', projectList);
  dialog.render();
}

function setJiraProject(projectId) {
  g_form.setValue('u_jira_project', projectId);
}

 

Client Script:

function onSubmit() {
  var projectId = $('select[name="project"]').val();
  if (projectId) {
    parent.setJiraProject(projectId);
    parent.document.getElementById('gsft_main').contentWindow.location.reload();
    return true;
  }
  else {
    alert('Please select a project.');
    return false;
  }
}

 

Thanks,

Rahul Kumar

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar

Hi Alon,

 

I am trying to provide you solution even while i am working. From anywhere so that your solution can be done.

 

Thanks for the comment

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar