We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Passing Parent Record SYSID into Modal Action

andrewbettc
Kilo Sage

Hi,

 

I have a Modal in the Project Workspace. It mimics the action of the legacy "Create from Library" UI Action and shows a list of Risk Statements from which, a user might want to create a project risk.

That modal has it's own List Action called Create Risks. The idea is that a user selects from the list and then clicks the button and the risk statement is associated with the Project. 

The problem is, I can't seem to get the parent project ID into the Modal. 

This is what it looks like for context:

AndrewBettcher_0-1769430743817.png

 

That declarative action (Create Risks) is a List Action implemented as a client script. I've tried setting a client state parameter with the sys_id of the parent and a handful of other ways to expose it but I feel like I'm missing something.

Does anyone know how this should be done?

This is the the current script running on click of the "Create Risks" button:

function onClick() {
    // 1) Read selected rows
    var selected = (typeof g_list !== 'undefined' && g_list.getChecked)
        ? g_list.getChecked()
        : '';

    if (!selected) {
        alert("Please select at least one risk statement.");
        return;
    }

    // 2) Get Project ID from Workspace Record Page state
    var projectId = "";
    try {
        // Record Page controller exposes state under one (or both) of these:
        projectId =
            (NOW && NOW.state && NOW.state.relatedTabContent && NOW.state.relatedTabContent.currentProjectId) ||
            (NOW && NOW.page && NOW.page.state && NOW.page.state.relatedTabContent && NOW.page.state.relatedTabContent.currentProjectId) ||
            "";
    } catch (e) {
        projectId = "";
    }

    if (!projectId) {
        alert("Could not determine project ID from Workspace state.");
        return;
    }

    // 3) Call existing Script Include
    var ga = new GlideAjax('sn_risk_advanced.AdvancedRiskPPMAJAX');
    ga.addParam('sysparm_name', 'createPPMRisks');
    ga.addParam('sysparm_projectId', projectId);
    ga.addParam('sysparm_content_ids', selected);

    ga.getXMLAnswer(function(answerStr) {
        var answer = {};
        try {
            answer = JSON.parse(answerStr || "{}");
        } catch (e) {
            alert("Unexpected server response.");
            return;
        }

        if (answer.error)             alert(answer.error);
        if (answer.newRiskMsg)        alert(answer.newRiskMsg);
        if (answer.failedRiskMsg)     alert(answer.failedRiskMsg);
        if (answer.existingRiskMsg)   alert(answer.existingRiskMsg);

        if (typeof g_list !== 'undefined' && g_list.refresh)
            g_list.refresh();
    });
}

 currentProjectId is my Client State Parameter.

1 REPLY 1

andrewbettc
Kilo Sage

Update - I noticed a configuration element on the listRelated component called ParentSysID:

AndrewBettcher_0-1769505602571.png


It seems obvious that this is what I'm supposed to be using but I can't find anything or work out any way to expose it and get that value. I guess it's the same problem as above.