To save with variable in save() function

Hi,

 

I want to save one variable which i created in with and values of that variable are getting update on basis of drop down.

I am using that variable(dataset) further to display something. But when i am trying to save any value in that dataset.

 

I am getting error

Expression evaluation error in rule 'rule_Test' (called by rules 'rule_test1' > 'rule_test2') at function a!applyComponents [line 176]: An error occurred while executing a save: Expression evaluation error: The save target must be a load() variable, process variable, or node input (or a rule input passed one of those three), but instead was:

 

What i sthe workaround to save the values of with variable instead to use load one as error says. 

  Discussion posts and replies are publicly visible

Parents
  • Hi sauravk,

    Can you please share your code snippet for better understanding of requirement?
  • load(
      
      with(
        
          a!gridRowLayout(
            id: ri!index,
            contents: {
              
              a!textField(
                label: "Hello" & ri!index,
                value: ri!masterDataSet[ri!index].name,
                saveInto: {
                  ri!masterDataSet[ri!index].name,
                  a!save(
                    ri!masterDataSet[ri!index].name,
                    upper(
                      ri!masterDataSet[ri!index].name
                    )
                  )
                  /*a!save(*/
                /*ri!testDataSet.name,*/
                /*save!value*/
                /*)*/
                  
                },
                
                validations: {
                     if(
                    contains(
                      touniformstring(
                        a!flatten(
                          {
                            remove(
                              ri!testDataSet.name,
                              wherecontains(ri!masterDataSet[ri!index].id,ri!testDataSet.id)
                            ),
                            ri!testDataSet.name,
                            ri!testDataSet.nameCopy
                          }
                        )
                      ),
                      tostring(
                        ri!masterDataSet[ri!index].name
                      )
                    ),
                    "This value already exists in the data",
                    ""
                  )
                }
              )
              ,
    		            a!textField(
                label: "Hii" & ri!index,
                value: ri!masterDataSet[ri!index].nameCopy,
                saveInto: {
                  ri!masterDataSet[ri!index].nameCopy,
                  a!save(
                    ri!masterDataSet[ri!index].nameCopy,
                    upper(
                      ri!masterDataSet[ri!index].nameCopy
                    )
                  )
                  /*a!save(*/
                /*ri!testDataSet.name,*/
                /*save!value*/
                /*)*/
                  
                },
                
                validations: {
                     if(
                    contains(
                      touniformstring(
                        a!flatten(
                          {
                            remove(
                              ri!testDataSet.nameCopy,
                              wherecontains(ri!masterDataSet[ri!index].id,ri!testDataSet.id)
                            ),
                            ri!testDataSet.name,
                            ri!testDataSet.nameCopy
                          }
                        )
                      ),
                      tostring(
                        ri!masterDataSet[ri!index].nameCopy
                      )
                    ),
                    "This value already exists in the data",
                    ""
                  )
                }
              )
              

  • Just to add here. This code i am calling from another rule inside with only. Where masterDataSet is getting prepare inside with .
    On my validation whenever i compare with existing values of masterDataSet than it will work fine. But when i try to give same new value which is not part of masterDataSet than validation rule is not working. So i tried to save updated value in this code. But as variable is defined in with in another rule and i am passing here.

    I hope i explained everything.
  • 0
    A Score Level 2
    in reply to sauravk
    How is the value of masterDataSet set? A query entity, editable grid? Again, is there a specific reason you are using a with() variable instead of a load()?

    If there is no reason to use a with() variable, then it may make sense to change it to a load(). Otherwise, you can create a new load() datasubset from the value in the with() variable in the SAIL you posted and append data to that variable.

    If possible though,check the impact of changing masterDataSet to a load() as that may be a much simpler path to take.
  • I am setting masterDataset through quertEntity but input of Q.E is dynamic. That's why i putting this in with otherwise masterDataSet will not be able to update dynamically.
  • 0
    A Score Level 2
    in reply to sauravk

    It will be able to update with dynamic values. **Edit: It will update if the queryEntity is placed in a saveInto; alternatively you could also use a button that is used to for requerying data**

    One approach you could take is 1) change masterDataSet to load(), 2) when you update the variables that drive the query entity in their saveIntos, requery the entity as well (if you are constantly updating the parameters of the qe, the amount of database transactions can be risky and depending on the size of the data being queried, can provide a bad user-experience). If you query the entity once, this may be the easiest way to achieve your goal. Below is an example of what I mean:

    load(
      local!datasubset,
      local!input1,
      local!input2,
      a!sectionLayout(
        contents: {
          a!columnsLayout(
            columns: {
              a!columnLayout(
                contents: {
                  a!textField(
                    label: "Input 1",
                    value: local!input1,
                    saveInto: local!input1
                  ),
                  a!textField(
                    label: "Input 2",
                    value: local!input2,
                    saveInto: local!input2
                  ),
                  a!buttonLayout(
                    primaryButtons: a!buttonWidget(
                      label: "Search",
                      saveInto: {
                        a!save(
                          local!datasubset,
                          rule!queryEntity(
                            local!input1,
                            local!input2
                          )
                        )
                      }
                    )
                  )
                }
              )
            }
          )
        }
      )
    )

    You can also copy the value of the masterDataSet value into a load variable, and make any changes to that variable's value. Then, you would run validations on the load variable that you define.

     

  • 0
    Certified Lead Developer
    in reply to sauravk

    Also, just as a suggestion, where you do this:

    saveInto: {
    ri!masterDataSet[ri!index].nameCopy,
    a!save(
    ri!masterDataSet[ri!index].nameCopy,
    upper(
    ri!masterDataSet[ri!index].nameCopy
    )
    )
    }

    You could replace this with simply:

    saveInto: {
      a!save(
        ri!masterDataSet[ri!index].nameCopy,
        upper(save!value)
      )
    }
Reply Children
No Data