How to Hide related list on-form load?

lucky24
Tera Contributor

Hi Team.

I have to hide particular related list when my affected user is "abel tuter"

for that I have tried with UI policy and on-load client script  even I have used on-change client script and converted into on-load client script.

That all working fine for on-change when i change the value of affected user but that all is not working for on-load when I load the form.

In PDI I am getting same issue.

My code is like below

On load client script-

find_real_file.png

 

UI Policy-

find_real_file.png

 

find_real_file.png

The name of related list I am getting from list control

find_real_file.png

 

Please help me here...?

1 ACCEPTED SOLUTION

function onLoad() {
    ScriptLoader.getScripts(['sn_si.SecurityIncidentConstants.jsdbx'], function() {

        var siConst = sn_si.SecurityIncidentConstants;
        g_form.hideRelatedLists();
        var group = "AFFECTED_ITEMS"; // the default
        var previousIncidentId = g_user.getClientData("incident"); // previous incident user were on
        var currentIncidentId = g_form.getUniqueValue(); // currently loaded incident

        if (previousIncidentId === currentIncidentId) {
            group = g_user.getClientData("group");
        } else {
            siConst.setLastRelatedList(group, currentIncidentId); // set state for the new incident
        }

        var lists = siConst.getList(group);

        if (typeof group === "undefined" || group === "") {
            g_form.showRelatedLists();
        } else {
            for (var i = 0; i < lists.length; i++)
                g_form.showRelatedList(lists[i]);
        }

        // your code
        var ab = g_form.getValue("affected_user");
        if (ab == "62826bf03710200044e0bfc8bcbe5df1") {
            g_form.showRelatedList("REL:c3979d351b310110d8de6464604bcbe0");
        } else {
            g_form.hideRelatedList("REL:c3979d351b310110d8de6464604bcbe0");
        }

    });
}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

18 REPLIES 18

Hi Ankur,

Still I am facing one issue,

When I am creating new record with another affected user so that time I am able to see that related list,

After on the same form I change the value and save the form then it is working.

In another word it is not working in first time.

Hi,

during creation i.e new record when form loads no related list would be shown by default as the record is not yet saved to database.

So I didn't get you are saying not working for first time

Can you share screenshot when it is not working?

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi ,

after submit new record first time.I my condition is not matching but I am able to see related list there.

find_real_file.png

 

I have change value and submit form again that time it is working.

find_real_file.png

Hi,

when you submit for first time did you check affected user is not 62826bf03710200044e0bfc8bcbe5df1

did it go inside the else condition which hides that

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Yes I have chacked. and it is going inside which hide that.

 

find_real_file.png

I observed one more thing after submit record first

time. I have to click on  elated link "show all related list.then all related list visible on the form

find_real_file.png

 

It is also OOB related link

 

find_real_file.png