-1

i want to use an array that contains all the fields and it will be hidden and use for loop to do it.

Inside the CRM MS i don't know how.

function hideShowPicklist(executionContext) {
    var RequiredField = GetAttributeValue(executionContext, "requiredtype");
    var ProcessField = GetAttributeValue(executionContext, "processtypecode");

    if (RequiredField == "0" && ProcessField == "4" || ProcessField == "5") {
        // it will Show the fields and set them as Required 
        SetAttrsVisibility(executionContext, "name", ",", true);
        SetAttrsVisibility(executionContext, "managername", ",", true);
        SetAttrsVisibility(executionContext, "fordealexecution", ",", true);
        SetAttrsVisibility(executionContext, "registrationaddress", ",", true);
      }
}

I want the code to be very short by using array and for loop.

Henk van Boeijen
  • 7,357
  • 6
  • 32
  • 42
  • Welcome to StackOverflow! Please try to explain a bit more in detail what you need to achieve. From your code example we cannot tell what function `SetAttrsVisibility` actually does and which arguments it supports. – Henk van Boeijen Nov 15 '22 at 10:32

1 Answers1

0

You are using a proprietary library I have no knowledge of and the precise workings of functions GetAttributeValue and SetAttrsVisibility is not fully clear, but I guess you are looking for a solution similar to this:

function hideShowPicklist(executionContext) {
    const processType = GetAttributeValue(executionContext, "processtypecode");

    const isRequired = (processType === "4" || processType === "5")
        && GetAttributeValue(executionContext, "requiredtype") === "0";

    [
        "name",
        "managername",
        "fordealexecution",
        "registrationaddress"
    ]
        .forEach(attributeName => {
            SetAttrsVisibility(executionContext, attributeName, ",", isRequired);
        });
}
Henk van Boeijen
  • 7,357
  • 6
  • 32
  • 42