How to refer to another field in the current record in the mapping edit js - Forum - Mobile - Progress Community

How to refer to another field in the current record in the mapping edit js

 Forum

How to refer to another field in the current record in the mapping edit js

This question is answered

I can't seem to find anywhere that shows how to do this (which may tell me something), but I would like to conditionally format the value to the bound control base on another fields value within the same record row of the current value.

I would also like to use that value without binding sometimes, like when you have a code and description and you would like to bind to the control, and also show the description (C - Closed kind of thing). 

To be clear, I invoke a jsdo read service and have that read service mappings for status_code to statusCodeLabel and go to Edit JS. In here I want to also display the status_code_description field in that label (mostly so that I can format it how I want and not have to use custom html to put labels side by side), but also in the event that I would want to format it based on another fields value.

Verified Answer
  • Hi Riche,

    If your usecase is to map two fields to same UI element and display data in one label by appending both field values ( statuscode - description like C - Closed). Then following is the way you can try in Edit JS.

    Map two fields to same label. As in following screen i have mapped CustNum and Name to same label.

    Written following in Edit JS script.

    var CustNum = localStorage.getItem("CustNum");
    if (!CustNum) {
    // we have new item, so we get CustNum as first value
    // next value will be Name
    localStorage.setItem("CustNum", value);
    return value;
    } else {
    // we already processed CustNum
    // next value will be CustNum for new item, so do cleaning
    localStorage.setItem("CustNum", '');
        return CustNum + ' - ' + value;
    }

    You will receive CustNum and Name following way in one label.

    Let me know if this answers your question.

    Thanks,

    Swathi.

All Replies
  • Hi Riche,

    If your usecase is to map two fields to same UI element and display data in one label by appending both field values ( statuscode - description like C - Closed). Then following is the way you can try in Edit JS.

    Map two fields to same label. As in following screen i have mapped CustNum and Name to same label.

    Written following in Edit JS script.

    var CustNum = localStorage.getItem("CustNum");
    if (!CustNum) {
    // we have new item, so we get CustNum as first value
    // next value will be Name
    localStorage.setItem("CustNum", value);
    return value;
    } else {
    // we already processed CustNum
    // next value will be CustNum for new item, so do cleaning
    localStorage.setItem("CustNum", '');
        return CustNum + ' - ' + value;
    }

    You will receive CustNum and Name following way in one label.

    Let me know if this answers your question.

    Thanks,

    Swathi.

  • It did indeed work. I missed the fact that it put the same TRANSFORMATION function for both fields and thought that it was just doing the last one, but this makes sense.

    One question though. I tried to break it by binding the description before the code and it still worked? How is it determining which one gets bound first? In the js file generated, it has the description first, yet at run-time debugging, it always hits the code field first. What if I had a dependency the other way?

  • Hi Riche,

    I have tried mapping two response values to same field and observed that order depends on the response listed. Like in above screen which i provided, CustNum is called first and Name is always called second time. The order of mapping CustNum first ("CustNum"(response) "Name"(response)) or second ("Name"(response) "CustNum"(response) )is not considered.

    Following is the other better way we can achieve this by mapping only one element (CustNum in my sample):

    var custNumValue = value;  // "value" is passed as first parameter and equals to the current  CustNumvalue

    var index = parseInt(element.attr("_idx").substr(1));   //  it is current index for processing row of dsCustomer.

    var custName = Read.data.dsCustomer.eCustomer[index].Name;   // instead of Read, you should write the name of data source which is connected to your service. You can see it on data source tab for your screen.

    return custNumValue + " - " + custName;  

    Thanks,

    Swathi.