g_modal - Create a reference field

Jonas Svensson
Tera Expert

Hello, 

I've created an UI Action for Agent Workspace which gives me some kind of result.

function onClick( g_form ) {
	g_modal.showFields({
        title: "Reference Field Test",
        fields: [{
            type: 'reference',
            name: 'caller_id',
            label: 'Label 0',
			referringTable: 'incident',
			referringRecordId: g_form.getUniqueValue(),
        }],
        size: 'lg'
    });
}

I do however want to reference my own table that I've created but I can't seem to get it to work. Here's what I've tried:

function onClick( g_form ) {
	g_modal.showFields({
        title: "Reference Field Test",
        fields: [{
            type: 'reference',
            name: 'u_name',
            label: 'Label 1',
			referringTable: 'sn_agent_workspace_external_users',
			referringRecordId: g_form.getUniqueValue(),
        }],
        size: 'lg'
    });
}

I was unable to find any documentation on this so that's why I'm asking a question here. Has anyone done something similar before that could point me in the right direction?

1 ACCEPTED SOLUTION

Sai Kumar B
Mega Sage
Mega Sage

Hi @jsfour 

This is a sample for the incident, try this as per your requirement.

function onClick(g_form) {

    var fields = [{
            type: 'reference',
            name: 'caller_id',  //Give your custom reference field
            label: getMessage('What is your name?'), //Give as per your requirement
            mandatory: true,
            reference: 'sys_user', //Give which table your custom field refers to
            referringTable: 'incident', //Give your custom table
            referringRecordId: g_form.getUniqueValue()
        }
    ];

    g_modal.showFields({
        title: "Enter your details",
        fields: fields,
        size: 'lg'
    }).then(function(fieldValues) {
        g_form.setValue('caller_id', fieldValues.updatedFields[2].value);
        g_form.save();
    });
}

For more Info Workspace UI ACtions

Please mark my answer as helpful/correct, if applicable.

Best regards,
Sai Kumar

View solution in original post

5 REPLIES 5

Sai Kumar B
Mega Sage
Mega Sage

Hi @jsfour 

This is a sample for the incident, try this as per your requirement.

function onClick(g_form) {

    var fields = [{
            type: 'reference',
            name: 'caller_id',  //Give your custom reference field
            label: getMessage('What is your name?'), //Give as per your requirement
            mandatory: true,
            reference: 'sys_user', //Give which table your custom field refers to
            referringTable: 'incident', //Give your custom table
            referringRecordId: g_form.getUniqueValue()
        }
    ];

    g_modal.showFields({
        title: "Enter your details",
        fields: fields,
        size: 'lg'
    }).then(function(fieldValues) {
        g_form.setValue('caller_id', fieldValues.updatedFields[2].value);
        g_form.save();
    });
}

For more Info Workspace UI ACtions

Please mark my answer as helpful/correct, if applicable.

Best regards,
Sai Kumar

Hello and thank you for your response.

My UI Action is in the Interaction view in Agent Workspace which doesn't have the reference field in it. I was hoping that I could just create a reference field within g_modal. Maybe that's not supposed to work?

I did just try this down below. The u_name is the name of the field in the custom table which is not present in the current Interaction. 

function onClick( g_form ) {
	g_modal.showFields({
        title: "Reference Field Test",
        fields: [{
            type: 'reference',
            name: 'u_name',  //Give your custom reference field
            label: getMessage('What is your name?'),
            mandatory: true,
            reference: 'sn_agent_workspace_external_users'
            referringTable: 'sn_agent_workspace_external_users',// I've tried with Interaction here as well without success
            referringRecordId: g_form.getUniqueValue()
        }],
        size: 'lg'
    });
}

Hello again.

I managed to solve it by adding the actual reference field to the Interaction table. I didn't think I would have to. I'll just hide it with an UI policy..

Thank you for your help!

An alternative way to trick the modal into allowing you to include a Reference field that DOESN'T exist on the g_form object would be to find another record that already references your custom table, for example for the following tables:

my_custom_table

my_custom_table_child

Where there is a field called my_custom_table_child.u_custom_parent which references my_custom_table you could do this:

function onClick( g_form ) {

g_modal.showFields({

        title: "Reference Field Test",

        fields: [{

            type: 'reference',

            name: 'u_custom_parent',  // this field exists on my referring table but NOT on my g_form table.

            label: getMessage('What is your name?'),

            mandatory: true,

            reference: 'my_custom_table',

            referringTable: 'my_custom_table_child',// Note that the referring table can be completely different to the g_form table 

            referringRecordId: '-1' // setting this to -1 tricks SN into thinking this is a brand new record

        }],

        size: 'lg'

    });

}

 

This has worked for me, but I'm finding that I always inherit the reference qualifier of the referring table's reference and I can't override it with query: '<encoded query string>' which is causing me some problems.