How to map CDT

Certified Associate Developer

Hello,

 

I have a requirement where I need to map data in one CDT to another. The two CDT's are as below

 

DS_SeparatedData which includes FieldIdentifier,DataValue,Datacaption and Keyidentifier - These values are coming from database, Now what I want is I want to map the value of FieldIdentifier and DattaValue manually from another variable. So my another variable would be: VD_SeparatedData which includes FieldIdentifier and DataValue. As per the value available in VD_SeparatedData variable, I want to update the value in DS_SeparatedData. for eg:

 Lets say my DS_SeparatedData consists of following value. i.e.

DS_SeparatedData

         FieldIdentifier:"Email"

         DataValue:abc@abc.com

         Datacaption: "Email ID"

        KeyIdentifier:2

 

VD_SeparatedData

       FieldIdentifier:"Email"

       DataValue:pqr@xyz.com

 

So I want DataValue in VD_SeparatedData variable to get updated in DS_SeparatedData as FieldIdentifier is same on both the variable. 

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer
    Hi for your requirement, you can create an expression rule, which will have your CDT as input parameter (which is having the value).

    Now use type!yourCDT(
    All property of your desired CDT: required value
    )

    Where type!yourCDT() is of your desired type CDT which you want to get as an output/response.

    This should do your job.
  • 0
    Certified Associate Developer
    in reply to aloks0189
    Hey Alok, Thanks for quick reply. The parameter which I will pass in expression rule should be my original CDT or the one where updated values are stored? Can you refer the above mentioned variables and implement it in your logic? That will clarify my all doubts. Thanks in advance
  • 0
    Certified Lead Developer
    in reply to viveku3486
    type!B is nothing but, will be used to form a the original variable. Let's say In your case actual cdt in which you want to copy the data, if its name is Employee then you could declare it as follows:


    type!Employee(
    empName: ri!otherCDT.empName,
    email: "abc@test.com",
    identifier: ri!otherCDT.eventIdentifier
    )

    Assume empName, email & identifier are the properties of your Target/Actual CDT where as empName, eventIdentifier is the property of your parameterized CDT which has the value

    Here type!Employee() will prepare a CDT object of type Employee

    Also, if you want to generate array of CDT then you need to make the use of looping functions such as: a!forEach(), apply() etc..


    Hope this will help you.
  • 0
    Certified Associate Developer
    in reply to mohamedt808
    Yes these two CDT's are multiple. Let me give a quick example


    CDT A:[Name=abc,Age=,Gender=Male],[Name=pqr,Age=,Gender=Female],[Name=xyz,Age=,Gender=Male] and so on.

    Similarly CDT B contains
    CDT B:[Name=abc,Age:40],[Name=jkl,Age:60],[Name=xyz,Age:20]

    As You can CDT A is my original CDT which contain all the columns whereas CDT B contains only 2 columns i.e Name and age. In CDT A you can see that "Age" property is blank. So what I need is that I need to update the values in CDT A with the matching values available in CDT B. My Final output would be something like

    [Name=abc,Age=40,Gender=Male],[Name=pqr,Age={Blank as no record for "pqr" is available in CDT B},Gender=Female],[Name=xyz,Age=20,Gender=Male] and so on.
  • 0
    Certified Associate Developer
    in reply to aloks0189
    Hey Alok,

    I don't want to map the data between two different CDT's. I want to map data between two variables of same CDT. Here my variables are different but their CDT is same. for eg, CDT A is one variable of type 'Employee' and CDT B is another variable of same type 'Employee'. Only difference is the number of properties they hold. In this case lets say CDT 'Employee' have 3 fields than variable CDT A contains all the three columns and CDT B contains only two columns. So whatever will be the value inside variable CDT B, I want to make the changes in CDT A.
  • As per what you are saying, you can use a simple index function and store these value in the actual CDT.Lets Say variable "a" (DS_SeparatedData?list) and Variable "b" (VD_SeparatedData?list) then store the result of following in variable a.

    a!forEach(
    items:ri!a,
    expression:{'type!{urn:com:appian:types}DS_SeparatedData'(
    Datacaption:ri!a[fv!index].Datacaption,
    KeyIdentifier:ri!a[fv!index].KeyIdentifier,
    DataValue: index(ri!b.DataValue,wherecontains(ri!a[fv!index].FieldIdentifier,ri!b.FieldIdentifier),""),
    FieldIdentifier:ri!a[fv!index].FieldIdentifier)}
    )
  • 0
    Certified Associate Developer
    in reply to mohamedt808
    Hello Mohamed,

    I tried your logic but its giving me error i.e Invalid index: Cannot index type Number (Integer) into type CDT2) (Data Outputs)
  • I am guessing that while trying it you have given the whole CDT as first parameter for index function , try specifying the parameter needed with dot notation .
  • 0
    Certified Associate Developer
    in reply to mohamedt808
    You mean one value at a time? I'm doing it like rule!MapManualValueToCDT(pv!firstCDT,pv!secondCDT) and then inside the rule i'm implementing your logic
  • Can you paste the rule logic you have writen here.
  • 0
    Certified Associate Developer
    in reply to mohamedt808
    a!forEach(
    items:ri!SeparatedData_CDT,
    expression:{'type!{urn:com:appian:types}WebLaunchParameters'(
    ProcessDataCaption: ri!SeparatedData_CDT[fv!index].ProcessDataCaption,
    FieldIdentifier: ri!SeparatedData_CDT[fv!index].FieldIdentifier,
    ProcessDataLaunch: ri!SeparatedData_CDT[fv!index].ProcessDataLaunch,
    ProcessDataOptional: ri!SeparatedData_CDT[fv!index].ProcessDataOptional,
    ProcessDataValue: index(ri!VD_Datasubset,wherecontains(ri!SeparatedData_CDT[fv!index].FieldIdentifier,ri!VD_Datasubset.FieldIdentifier),""),
    KeyFormAttributeType: ri!SeparatedData_CDT[fv!index].KeyFormAttributeType,
    FormAttributeValue: ri!SeparatedData_CDT[fv!index].FormAttributeValue
    )}
    )
  • Try this ,


    a!forEach(
    items:ri!SeparatedData_CDT,
    expression:{'type!{urn:com:appian:types}WebLaunchParameters'(
    ProcessDataCaption: ri!SeparatedData_CDT[fv!index].ProcessDataCaption,
    FieldIdentifier: ri!SeparatedData_CDT[fv!index].FieldIdentifier,
    ProcessDataLaunch: ri!SeparatedData_CDT[fv!index].ProcessDataLaunch,
    ProcessDataOptional: ri!SeparatedData_CDT[fv!index].ProcessDataOptional,
    ProcessDataValue: index(ri!VD_Datasubset.ProcessDataValue,wherecontains(ri!SeparatedData_CDT[fv!index].FieldIdentifier,ri!VD_Datasubset.FieldIdentifier),""),
    KeyFormAttributeType: ri!SeparatedData_CDT[fv!index].KeyFormAttributeType,
    FormAttributeValue: ri!SeparatedData_CDT[fv!index].FormAttributeValue
    )}
    )
Reply
  • Try this ,


    a!forEach(
    items:ri!SeparatedData_CDT,
    expression:{'type!{urn:com:appian:types}WebLaunchParameters'(
    ProcessDataCaption: ri!SeparatedData_CDT[fv!index].ProcessDataCaption,
    FieldIdentifier: ri!SeparatedData_CDT[fv!index].FieldIdentifier,
    ProcessDataLaunch: ri!SeparatedData_CDT[fv!index].ProcessDataLaunch,
    ProcessDataOptional: ri!SeparatedData_CDT[fv!index].ProcessDataOptional,
    ProcessDataValue: index(ri!VD_Datasubset.ProcessDataValue,wherecontains(ri!SeparatedData_CDT[fv!index].FieldIdentifier,ri!VD_Datasubset.FieldIdentifier),""),
    KeyFormAttributeType: ri!SeparatedData_CDT[fv!index].KeyFormAttributeType,
    FormAttributeValue: ri!SeparatedData_CDT[fv!index].FormAttributeValue
    )}
    )
Children