Passing Parent Record SYSID into Modal Action

Andrew Bettcher
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.

0 REPLIES 0