The CreatorCon Call for Content is officially open! Get started here.

How to add get parentSysId to the Link to Destination event handler

Annette Kitzmil
Tera Guru

Hello,

This is probably a simple question for some, but I can't seem to figure this out.  I have created a uxf declarative action for a related list.  This has an add on event mapping to a handled event in ui builder that is mapped to a link to destination event.  Below is my current script, but I need to pass the parent record sys_id so that I am able to prefill the fields on the form that is getting opened up as most of the fields are coming from the parent table on the child record form that is being opened.  I was trying to set this up so that the parent sysId gets passed in the URL so I could use it for a business rule to prefill the values.  So two questions please.

1) how do I update the script below so it passes the parent record sysId which is the page I am on when the button is getting clicked on the related list?

2) Is there a better method for prefilling the values on the child record page from the parent record than a Business Rule?

 
function evaluateEvent({api, event}) {
    return {
        route: "sip-infraction-record",
        fields: {
        sysId: "-1" ,
        table: "x_mtbr_ebs_sip_0_sip_infractions"
    },
        params: {
        fields: null ,
        query: null ,
        route: "sip-infraction-record"
    },
        redirect: null,
        passiveNavigation: null,
        title: null,
        multiInstField: null,
        targetRoute: null,
        external: null,
        navigationOptions: null
    };
}

 

Thanks,

Annette

 

3 REPLIES 3

kaushal_snow
Mega Sage

Hi @Annette Kitzmil ,

 

To pass the parent record's sys_id when navigating from a related list in UI Builder, you can modify your evaluateEvent function to include the parent sys_id in the params object. Here's how you can do it:

 

function evaluateEvent({ api, event }) {
const parentSysId = api.getPage().sys_id; // Retrieve the parent sys_id

return {
route: "sip-infraction-record",
fields: {
sysId: "-1",
table: "x_mtbr_ebs_sip_0_sip_infractions",
},
params: {
parentSysId: parentSysId, // Pass the parent sys_id as a parameter
},
redirect: null,
passiveNavigation: null,
title: null,
multiInstField: null,
targetRoute: null,
external: null,
navigationOptions: null,
};
}


In this, api.getPage().sys_id retrieves the sys_id of the current page (which is the parent record). This value is then passed as a parameter (parentSysId) to the destination route. On the destination page, you can access this parameter to prefill the form fields using a Business Rule or a UI Script. For example, in a Business Rule, you can use current.parent_security_incident = params.parentSysId; to set the parent reference field.....

 

If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.

 

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/

Thank you, this didn't work, but got me to the point I needed.  I had to add the parentSysid parameter to the child record page as a required parameter.  Then I was able to go to the parent record page and set the parentSysId that now showed for the Link to Destination to the sys_id and now it shows in the URL.

 

avensisd
Tera Contributor

You need to dynamically pass the sysId of the active parent form into the declarative action. To do this, you need access to the page context (the current recordId).