UI action on Table A to insert on Table B
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
I have a scoped app. I have Table A (Project) and it has a scripted (Relationship) Related List that is a list of projects associated with the parent project.
I've created a UI action to allow the user to insert new associations to Table B (Associated Projects). The UI Action opens a modal that is for Table B, but on submit, it creates a new Table A (Project) entry. This is not what I want. It should create a new Table B (Associated Projects) entry.
What's going on here? What am I missing?
UI Action:
Name: Edit Associations
Table: Project[x_somescope_project]
Action name: edit_associations
x | Active
x | Show insert
x | Show update
x | Client
x | List v2 Compatible
x | List banner button
Onclick: openProjectM2M()
Condition: parent.isValidRecord()
Script
function openProjectM2M() {
var targetTable = 'x_scope_m2m_projects';
var gdw = new GlideModal('glide_list_collect'); //??
// var gdw = new GlideModal('x_scope_m2m_projects');
gdw.setTitle('Add Associated Projects');
gdw.setPreference('title', 'Project Selection');
gdw.setPreference('table', targetTable);
gdw.setPreference('query', 'active=true');
gdw.render();
}
ver. Yokohama
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Heyhey,
The modal you are opening is referencing a UI page. As you've commented //?? i am assuming you are not 100% on what that means. So let me guide you to the likely solution.
A GlideModal opens a UI page of your choice. In the code you've provided this is "glide_list_collect". This is the name of the UI page the modal opens. Within this ui page definition it is likely that you have indeed a serverside script responsible for creating the final record. You can check there, which table is used to create the final record.
My guess is, that this ui page does not use the correct table in the server script.
Hope this helps.
Regards
Fabian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a week ago
After much searching, here's my current answer, which I'll probably revise in the future...
/**
* Name : Associate
* Table : x_somescope_project
* Order : 200
* assoc_project
* Active : true
* Show insert : true
* Show update : true
* List v2 Compatible : true
* List banner button : true
* Hint : Associate a project
* Onclick : assoc_project()
* Condition : [gs.hasRole('x_somescope.project_user') && current.getRecordClassName() == 'x_somescope_project']
*/
// Script
function assoc_project() {
var gmf = new GlideModalForm("Create Association", 'x_somescope_project_associations');
gmf.setPreference('sysparm_query', 'project_a=' + g_form.getUniqueValue());
gmf.setPreference('sys_id', '-1');
// Add callback to refresh only on successful submission
gmf.setCompletionCallback(function() {
// Refresh the current page
location.reload();
});
gmf.render();
}
