error in function

Certified Associate Developer

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Associate Developer
    in reply to shifa

    is it because of not using index() function 

  • 0
    Certified Lead Developer
    in reply to shifa

    Honestly the small snippet you've posted in your screenshot doesn't tell us much.  What type of field is it?  What are you trying to accomplish?  Can you post a larger code snippet, preferably in a Code Box?

  • 0
    Certified Associate Developer
    in reply to Mike Schmitt

    /*Row layout for each row of the Person grid to add new Person.*/
    =load(
      local!tmods_user: if(
          or(
            rule!SCE_Case_isEmpty(ri!items),
            rule!SCE_Case_isEmpty(ri!items[ri!index].id)
          ),
          if(
            rule!SCE_Case_isEmpty(ri!items[ri!index].emp_num),
            null,
            rule!TMODS_getUserByTeamMemberId(ri!items[ri!index].emp_num)
          ),
          rule!TMODS_getUsers(
            value: ri!items[ri!index].id,
            batchSize:1
          )
      ),
      local!identified: if(ri!items[ri!index].type=cons!SCE_CASE_EMP_TYPES[1], true, false),
      a!gridRowLayout(
      /*Index of the row*/
      id: ri!index,
      contents: {
        a!dropdownField_20r2(
          label: rule!SCE_Case_translateKey(
            "translate.label.type"
          ) & ri!index,
          choiceLabels: a!forEach(
            cons!SCE_CASE_EMP_TYPES,
            rule!SCE_Case_convertEnToFr(
              fv!item
            )
          ),
          choiceValues: cons!SCE_CASE_EMP_TYPES,
          placeholderLabel: rule!SCE_Case_translateKey(
            cons!SCE_CASE_PLACEHOLDER_VALUE
          ),
          value: ri!items[ri!index].type,
          saveInto: {
            /*This is where we destroy the row of data when the user flips the type */
            a!save(ri!items[ri!index],null),
            /* This is where we save the type */
            ri!items[ri!index].type,
            if(
              ri!items[ri!index].type = cons!SCE_CASE_EMP_TYPES[1],
              {
                /*when identified*/
                a!save(
                  ri!items[ri!index].affiliation,
                  cons!SCE_CASE_AFFILIATION[1]
                ),
                a!save(
                  local!identified,
                  true()
                )
              },
              {
            
                a!save(
                  ri!items[ri!index].affiliation,
                  cons!SCE_CASE_AFFILIATION[2]
                ),
                a!save(
                  local!identified,
                  false()
                )
              }
            )
          },
          required: true
        ),
        if(
          local!identified,
          a!textField(
            label: rule!SCE_Case_translateKey(
              "translate.label.affiliation"
            ) & ri!index,
            value: ri!items[ri!index].affiliation,
            saveInto: ri!items[ri!index].affiliation,
            readOnly: true
          ),
          a!dropdownField_20r2(
            label: rule!SCE_Case_translateKey(
              "translate.label.affiliation"
            ) & ri!index,
            choiceLabels: a!forEach(
              cons!SCE_CASE_AFFILIATION,
              rule!SCE_Case_translateKey(
                fv!item
              )
            ),
            choiceValues: cons!SCE_CASE_AFFILIATION,
            placeholderLabel: rule!SCE_Case_translateKey(
              cons!SCE_CASE_PLACEHOLDER_VALUE
            ),
            value: ri!items[ri!index].affiliation,
            saveInto: {
              ri!items[ri!index].affiliation,
              a!save(
                ri!items[ri!index].last_updated_by,
                loggedInUser()
              )
              ,
              a!save(
                ri!items[ri!index].last_updated_on,
                now()
              )
            },
            required: true
          )
        ),
        if(
          local!identified,
          a!pickerFieldCustom(
            label: rule!SCE_Case_translateKey(
              "translate.label.search"
            ) & ri!index,
            maxSelections: 1,
            suggestFunction: rule!TMODS_customPicker(
              filter: _
            ),
            selectedLabels: if(
                rule!SCE_Case_isEmpty(
                  local!tmods_user
                ),
                null,
                local!tmods_user.preferred_given_name & " " & local!tmods_user.family_name & " (" & local!tmods_user.enterprise_login_id & ") "
              ),
            value: if(
              rule!SCE_Case_isEmpty(
                local!tmods_user
              ),
              null,
              local!tmods_user.preferred_given_name & " " & local!tmods_user.family_name & " (" & local!tmods_user.enterprise_login_id & ") "
            ),
            saveInto: {
              local!tmods_user,
              a!save(
                ri!items[ri!index].affiliation,
                if(
                  rule!SCE_Case_isEmpty(local!tmods_user),
                  cons!SCE_CASE_AFFILIATION[1],
                  if(
                    or(/*retired or terminated employees*/
                      local!tmods_user.employment_status_cd="RET", 
                      local!tmods_user.employment_status_cd="TERM"
                    ),
                    cons!SCE_CASE_AFFILIATION[3],
                    cons!SCE_CASE_AFFILIATION[1]
                  )
                )
              ),
              a!save(
                ri!items[ri!index].first_name,
                if(
                  rule!SCE_Case_isEmpty(local!tmods_user),
                  null,
                  local!tmods_user.given_name
                )
              ),
              a!save(
                ri!items[ri!index].last_name,
                if(
                  rule!SCE_Case_isEmpty(local!tmods_user),
                  null,
                  local!tmods_user.family_name
                )
              ),
              a!save(
                ri!items[ri!index].pref_name,
                if(
                  rule!SCE_Case_isEmpty(local!tmods_user),
                  null,
                  local!tmods_user.preferred_given_name
                )
              ),
              a!save(
                ri!items[ri!index].job_title,
                if(
                  rule!SCE_Case_isEmpty(local!tmods_user),
                  null,
                  local!tmods_user.position_title
                )
              ),          
              a!save(
                ri!items[ri!index].phone,
                if(
                  rule!SCE_Case_isEmpty(local!tmods_user),
                  null,
                  local!tmods_user.work_phone_no
                )
              ),     
              a!save(
                ri!items[ri!index].email,
                if(
                  rule!SCE_Case_isEmpty(local!tmods_user),
                  null,
                  local!tmods_user.work_email_address_text
                )
              ),   
              a!save(
                ri!items[ri!index].telus_id,
                if(
                  rule!SCE_Case_isEmpty(local!tmods_user),
                  null,
                  local!tmods_user.enterprise_login_id
                )
              ),
              a!save(
                ri!items[ri!index].emp_num,
                if(
                  rule!SCE_Case_isEmpty(local!tmods_user),
                  null,
                  local!tmods_user.team_member_id
                )
              ),
              a!save(
                ri!items[ri!index].person_type,
                if(
                  rule!SCE_Case_isEmpty(local!tmods_user),
                  null,
                  ri!items[ri!index].person_type
                )
              ),
              if(
                or(
                  rule!SCE_Case_isBlank(ri!items[ri!index]),
                  rule!SCE_Case_isBlank(ri!items[ri!index].person_id)
                ),
                {
                  /* add a new TMOS person */
                  a!save(
                    ri!items[ri!index].person_id,
                    null
                  ),
                  a!save(
                    ri!items[ri!index].added_by,
                    loggedInUser()
                  ),
                  a!save(
                    ri!items[ri!index].added_on,
                    now()
                  )
                },
                {
                /*update an existing TMODS person - DO NOTHERE here, so won't duplicate the person*/
                }
              ),
              a!save(
                ri!items[ri!index].last_updated_by,
                loggedInUser()
              ),
              a!save(
                ri!items[ri!index].last_updated_on,
                now()
              ),
              a!save(
                ri!items[ri!index].is_active,
                true()
              ),
              a!save(
                ri!items[ri!index].type,
                cons!SCE_CASE_EMP_TYPES[1]
              ),
              a!save(
                local!identified,
                true()
              )
            },
            required: true
          ),
          a!pickerFieldCustom(
            label: rule!SCE_Case_translateKey(
              "translate.label.preferredName"
            ) & ri!index,
            placeholder: "Type to select the Person's details",
            maxSelections: 1,
            suggestFunction: rule!SCE_Case_personCustomPicker(
              filter: _
            ),
            selectedLabels: if(
              or(
                rule!SCE_Case_isEmpty(ri!items),
                rule!SCE_Case_isBlank(ri!items[ri!index].last_name)
              ),
              null,
              ri!items[ri!index].pref_name & " " & ri!items[ri!index].last_name
            ),
            value: if(
              or(
                rule!SCE_Case_isEmpty(ri!items),
                rule!SCE_Case_isBlank(ri!items[ri!index].last_name)
              ),
              null,
              ri!items[ri!index].pref_name & " " & ri!items[ri!index].last_name
            ),
            saveInto: {
              ri!items[ri!index],
              if(
                or(
                  /* person not found i.e. new person */
                  rule!SCE_Case_isEmpty(ri!items[ri!index]),
                  rule!SCE_Case_isBlank(ri!items[ri!index].person_id),
                  /* person found but not in this case */
                  ri!items[ri!index].case_id <> ri!caseId
                ),
                {
                  /*clear person picker or add a new person*/
                  a!save(
                    ri!items[ri!index].person_id,
                    null
                  ),
                  a!save(
                    ri!items[ri!index].added_by,
                    loggedInUser()
                  ),
                  a!save(
                    ri!items[ri!index].added_on,
                    now()
                  )
                },
                {}
              ),
              a!save(
                ri!items[ri!index].last_updated_by,
                loggedInUser()
              ),
              a!save(
                ri!items[ri!index].last_updated_on,
                now()
              ),
              a!save(
                ri!items[ri!index].is_active,
                true()
              ),
              a!save(
                ri!items[ri!index].type,
                cons!SCE_CASE_EMP_TYPES[2]
              ),
              a!save(
                local!identified,
                false()
              )
            },
            required: true
          )
        ),
        a!textField(
          label: rule!SCE_Case_translateKey(
            "translate.label.userID"
          ) & ri!index,
          value: ri!items[ri!index].telus_id,
          saveInto: {
            ri!items[ri!index].telus_id,
            a!save(
              ri!items[ri!index].last_updated_by,
              loggedInUser()
            ),
            a!save(
              ri!items[ri!index].last_updated_on,
              now()
            )
          },
          readOnly: true    
        ),
        a!textField(
          label: rule!SCE_Case_translateKey(
            "translate.label.firstName"
          ) & ri!index,
          value: ri!items[ri!index].first_name,
          saveInto: {
            ri!items[ri!index].first_name,
            a!save(
              ri!items[ri!index].is_active,
              true()
            ),
            a!save(
              ri!items[ri!index].last_updated_by,
              loggedInUser()
            ),
            a!save(
              ri!items[ri!index].last_updated_on,
              now()
            )
          },
          readOnly:local!identified,
          required: not(local!identified)
        ),
        a!textField(
          label: rule!SCE_Case_translateKey(
            "translate.label.lastName"
          ) & ri!index,
          value: ri!items[ri!index].last_name,
          saveInto: {
            ri!items[ri!index].last_name,
            a!save(
              ri!items[ri!index].last_updated_by,
              loggedInUser()
            ),
            a!save(
              ri!items[ri!index].last_updated_on,
              now()
            )
          },
          readonly: local!identified,
          required: not(local!identified)
        ),  
        a!textField(
          label: rule!SCE_Case_translateKey(
            "translate.label.preferredName"
          ) & ri!index,
          value: ri!items[ri!index].pref_name,
          saveInto: {
            ri!items[ri!index].pref_name,
            a!save(
              ri!items[ri!index].last_updated_by,
              loggedInUser()
            ),
            a!save(
              ri!items[ri!index].last_updated_on,
              now()
            )
          },
          readonly: local!identified
        ),    
        a!textField(
          label: rule!SCE_Case_translateKey(
            "translate.label.jobTitle"
          ) & ri!index,
          value: ri!items[ri!index].job_title,
          saveInto: {
            ri!items[ri!index].job_title,
            a!save(
              ri!items[ri!index].last_updated_by,
              loggedInUser()
            ),
            a!save(
              ri!items[ri!index].last_updated_on,
              now()
            )
          },
          readonly:local!identified
        ),
        a!textField(
          label: rule!SCE_Case_translateKey(
            "translate.label.phoneNumber"
          ) & ri!index,
          value: ri!items[ri!index].phone,
          saveInto: {
            ri!items[ri!index].phone,
            a!save(
              ri!items[ri!index].last_updated_by,
              loggedInUser()
            ),
            a!save(
              ri!items[ri!index].last_updated_on,
              now()
            )
          },
          readonly:local!identified
        ),
        a!textField(
          label: rule!SCE_Case_translateKey(
            "choiceList.attachType.email"
          ) & ri!index,
          value: ri!items[ri!index].email,
          saveInto: {
            ri!items[ri!index].email,
            a!save(
              ri!items[ri!index].last_updated_by,
              loggedInUser()
            ),
            a!save(
              ri!items[ri!index].last_updated_on,
              now()
            )
          },
          readonly:local!identified,
          validations: rule!SCE_Case_validateEmail(
            ri!items[ri!index].email
          )
        ),
        a!textField(
          label: rule!SCE_Case_translateKey(
            "translate.label.company"
          ) & ri!index,
          value: ri!items[ri!index].company,
          saveInto: {
            ri!items[ri!index].company,
            a!save(
              ri!items[ri!index].last_updated_by,
              loggedInUser()
            ),
            a!save(
              ri!items[ri!index].last_updated_on,
              now()
            )
          },
          readonly: local!identified
        ),
        a!dropdownField_20r2(
          label: rule!SCE_Case_translateKey(
            "translate.label.personType"
          ) & ri!index,
          choiceLabels: a!forEach(
            cons!SCE_CASE_PERSON_TYPES,
            rule!SCE_Case_convertEnToFr(
              fv!item
            )
          ),
          choiceValues: cons!SCE_CASE_PERSON_TYPES,
          placeholderLabel: rule!SCE_Case_translateKey(
            cons!SCE_CASE_PLACEHOLDER_VALUE
          ),
          value: ri!items[ri!index].person_type,
          saveInto: {
            ri!items[ri!index].person_type,
            a!save(
              ri!items[ri!index].last_updated_by,
              loggedInUser()
            ),
            a!save(
              ri!items[ri!index].last_updated_on,
              now()
            )
          },
          required: true
        ),
        a!imageField(
          label: rule!SCE_Case_translateKey(
            "translate.value.delete"
          ) & ri!index,
          images: a!documentImage(
            document: a!iconIndicator(
              "REMOVE"
            ),
            altText: rule!SCE_Case_translateKey(
              "translate.value.remove"
            ),
            link: a!dynamicLink(
              value: ri!index,
              saveInto: {
                if(
                  rule!SCE_Case_isBlank(
                    ri!items[ri!index].person_id
                  ),
                  {},
                  {
                    a!save(
                      ri!items[ri!index].is_active,
                      false()
                    ),
                    a!save(
                      ri!items[ri!index].last_updated_by,
                      loggedInUser()
                    ),
                    a!save(
                      ri!items[ri!index].last_updated_on,
                      now()
                    ),
                    a!save(
                      ri!deletedPersonDetails,
                      append(
                        ri!deletedPersonDetails,
                        ri!items[ri!index]
                      )
                    )
                  }
                ),
                a!save(
                  ri!items,
                  remove(
                    ri!items,
                    save!value
                  )
                ),
                /* When modifying the size of the array used in a!applyComponents,  */
                /* make the same change in the "token" array variable               */
                a!save(
                  ri!itemsToken,
                  remove(
                    ri!itemsToken,
                    save!value
                  )
                )
              }
            )
          ),
          size: "ICON"
        )
      }
    )
    )

    This code give me error:

    May be not used index. 

  • 0
    Certified Lead Developer
    in reply to shifa

    From the error message, I would assume that ri!items being passed to SCE_Case_isEmpty is null.

  • 0
    Certified Associate Developer
    in reply to Mathieu Drouin

    how it is resolved

  • 0
    Certified Lead Developer
    in reply to shifa

    If ri!items is empty, then any use of square brackets i.e. "ri!items[ri!index]" will cause this issue.  The easiest thing here would be to ensure ri!items is not empty.  If you're using the interface designer, provide it some value after clicking the "test" button and see whether the errors go away.

    Who originally designed this interface?  It's doing some pretty complicated things and it is NOT designed to handle an empty "ri!items" value without breaking.  Can you consult whoever originally designed it and seek to gain a better understanding of its functionality from them?  It's really difficult for us here to explain all the little details, even when we can see things that are wrong.

Reply
  • 0
    Certified Lead Developer
    in reply to shifa

    If ri!items is empty, then any use of square brackets i.e. "ri!items[ri!index]" will cause this issue.  The easiest thing here would be to ensure ri!items is not empty.  If you're using the interface designer, provide it some value after clicking the "test" button and see whether the errors go away.

    Who originally designed this interface?  It's doing some pretty complicated things and it is NOT designed to handle an empty "ri!items" value without breaking.  Can you consult whoever originally designed it and seek to gain a better understanding of its functionality from them?  It's really difficult for us here to explain all the little details, even when we can see things that are wrong.

Children
No Data