Set the Array data in Rule Input after button click.

Hi,

I have One Array in local variable. 

like 

data=[type:Opportunity,Name:Dickenson Mobile Generators,Account:[type:Account,Name:Dickenson plc],Amount:15000.0];
         [type:Opportunity,Name:United Oil Office Portable Generators,Account:[type:Account,Name:United Oil & Gas Corp.],Amount:125000.0];
         [type:Opportunity,Name:Express Logistics Standby Generator,Account:[type:Account,Name:Express Logistics and Transport],Amount:220000.0];
         [type:Opportunity,Name:GenePoint Standby Generator,Account:[type:Account,Name:GenePoint],Amount:85000.0];
         [type:Opportunity,Name:Grand Hotels Kitchen Generator,Account:[type:Account,Name:Grand Hotels & Resorts Ltd],Amount:15000.0], identifiers=1; 2; 3; 4; 5]

and want to store this five opportunity data in rule input to insert into the Appian Cloud Database separately(Five row in appian Cloud Database) after clicking on submit button or on load of form.

to implement this i created one rule input like:

  

but after clicking on submit button i get the all data in rule input five time with merge data . like

and i need this data in rules input in five time with different values like 

code on submit button:

so how i can do this.

 

 

 

  Discussion posts and replies are publicly visible

  • Hi Gawali,

    On submit save your entire local variable to your rule input, we don't need to index each attribute from the local variable.

    Example: a!save(ri!SID_OppDataNew, local!opportunities.data)

    Hope this helps.


    Thanks
    Vijay
  • I have forgotten to say one thing, I would suggest you convert your local variable into the respective CDT type and then try to save it into rule input.
  • Thanks Vijay.
    to convert local variable into CDT i try this
    saveInto:
    {
    a!save(
    ri!SID_OppDataNew_RI,
    fn!cast(fn!typeof({type!SID_oppCDT(ri!SID_OppDataNew_RI)}),local!opportunities.data)
    )
    },

    but it save all null value,

    this my code is correct or missing something.

  • 0
    Certified Lead Developer
    in reply to Gawali

    I've ran into this problem a lot. You need a rule whose output is of the type yourCDT. The only way to do that is a type constructor. You need to make a new expression rule that only contains a type!yourCDT. It takes inputs of all the values that make your CDT, and doesn't do anything but put them back into the SAME CDT.  Note: It has to return type 1 single yourCDT all by itself.  You CAN'T do the list of them part yet.

    After you've built that, make your a!save. The target is your rule input, the value is an a!forEach that runs the separate type constructor expression rule you made on each row in your local!CDT list one at a time. After it's gone through all of the items, the a!forEach will return a LIST of the single yourCDT items.  I know it sounds more time consuming than it needs to be, but this is what I was able to get to finally work.

    (This is the only means I have ever discovered for changing one element of a CDT which is in a list. A list of 5 employees with last names, and I want to capitalize each of them, I have to do it THIS way. I have to build out a type constructor to save everything else back to where it already was and save proper(lastName) back to where it already was, one CDT item at a time.)

  • Please give a try passing the only CDT type empty constructor as below

    Example: fn!cast(fn!typeof({type!SID_oppCDT()}),local!opportunities.data)

    Thanks
    Vijay
  • yes @Vijay

    I tried

    Example: fn!cast(fn!typeof({type!SID_oppCDT()}),local!opportunities.data) but it save all null value.

  • Gawali,

    Could you please share the XSD of your CDT?
  • My XSD File 

    xsd:schema xmlns:xsd="www.w3.org/.../XMLSchema" xmlns:tns="urn:com:appian:types" targetNamespace="urn:com:appian:types">

    <xsd:complexType name="SID_oppCDT">
    <xsd:annotation>
    <xsd:documentation><![CDATA[Opp cdt]]></xsd:documentation>
    </xsd:annotation>
    <xsd:sequence>
    <xsd:element name="id" nillable="true" type="xsd:int">
    <xsd:annotation>
    <xsd:appinfo source="appian.jpa">@Id @GeneratedValue</xsd:appinfo>
    </xsd:annotation>
    </xsd:element>
    <xsd:element name="name" nillable="true" type="xsd:string">
    <xsd:annotation>
    <xsd:appinfo source="appian.jpa">@Column(length=255)</xsd:appinfo>
    </xsd:annotation>
    </xsd:element>
    <xsd:element name="accountName" nillable="true" type="xsd:string">
    <xsd:annotation>
    <xsd:appinfo source="appian.jpa">@Column(length=255)</xsd:appinfo>
    </xsd:annotation>
    </xsd:element>
    <xsd:element name="amount" nillable="true" type="xsd:string">
    <xsd:annotation>
    <xsd:appinfo source="appian.jpa">@Column(length=255)</xsd:appinfo>
    </xsd:annotation>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:schema>

  • Hi Gawali,

    Please check out the code below. Here the testCdt is your CDT.

    load(
      local!testVar: {
        /*  Your Data  */
        data: {
          {
            type: "Opportunity",
            Name: "DickensonMobileGenerators",
            Account: {
              type: "Account",
              Name: "Dickensonplc"
            },
            Amount: 15000.0
          },
          {
            type: "Opportunity",
            Name: "UnitedOilOfficePortableGenerators",
            Account: {
              type: "Account",
              Name: "UnitedOil & GasCorp."
            },
            Amount: 125000.0
          },
          {
            type: "Opportunity",
            Name: "ExpressLogisticsStandbyGenerator",
            Account: {
              type: "Account",
              Name: "ExpressLogisticsandTransport"
            },
            Amount: 220000.0
          },
          {
            type: "Opportunity",
            Name: "GenePointStandbyGenerator",
            Account: {
              type: "Account",
              Name: "GenePoint"
            },
            Amount: 85000.0
          },
          {
            type: "Opportunity",
            Name: "GrandHotelsKitchenGenerator",
            Account: {
              type: "Account",
              Name: "GrandHotels & ResortsLtd"
            },
            Amount: 15000.0
          }
        },
        identifiers: {
          1,
          2,
          3,
          4,
          5
        }
      },
      a!buttonLayout(
        secondaryButtons: {
          a!buttonWidget(
            label: "submit",
            saveInto: {
              a!save(
                ri!testCdt,
                a!forEach(
                  items: local!testVar.data,
                  expression: {
                    name: fv!item.Name,
                    accountName: fv!item.Account.Name,
                    amount: fv!item.Amount
                  }
                )
              )
            }
          )
        }
      )
    )
     

    Hope this helps!

  • After seeing your XSD file, the data structure you have in the local variable doesn't match with this XSD.

    Please try to save your local variable to the appropriate CDT type.