Hi - While changing value using a!save(), I see different output for a!buttonWid

Hi - While changing value using a!save(), I see different output for a!buttonWidget() and a!buttonWidgetSubmit(). Isn't it a weird behaviour? But, I am facing this issue. itemsCart is an array of defined CDT where vehicle is a field. When I code inside a!buttonWidgetSubmit() then value is coming as repeated (which is equal to number of records in itemsCart). But, I am getting correctly when I put this code inside a!buttonWidget(). Please find the attached code. I have given sample value as well. Please share your thought. Thanks.


Code.txt

OriginalPostID-167232

OriginalPostID-167232

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer
    Hi Rajesh, I guess it is not a problem with buttonWidget or buttonWidgetSubmit. It is problem with how you are saving a value into a field in the CDT. "ri!itemsCart.vehicle" is an array type. So we could not save direct value into array type variable. You might save like "a!save(ri!itemsCart.vehicle, {"91524",""})" or depends on your requirement.
  • My question is why it is behaving differentyly for buttonWidget() and buttonWidgetSubmit()?
  • I'm not seeing different behavior when I try your code, Rajesh. I used your sample values for the rule input, and first tried to execute the button, which broke. This is because we are trying to save one element into an array of elements at the index vehicle. If we think of each cdt as a box with different sections (vehicle would be a section), with the save written as a!save(ri!itemsCart.vehicle, "91524"), we are saying to store "91524" into the section vehicle, but we have two boxes, and we don't know into which box to update the section. I would suggest keeping a local index variable to keep up with which box to update, so your a!save is a!save(ri!itemsCart[local!index].vehicle, "91524"). I know this doesn't directly address your question, but I think you may be seeing different output because your array size may be different between the time you use buttonWidget and buttonWidgetSubmit. To confirm, try switching their positions/using them in the opposite order. a!save should work identically for both button types, and without seeing the full implementation where your weird behavior is happening, my best guess is that your array changes between use of the buttons, so your target location is different, and the save acts as it should, but not as expect, as the target data is different from expected.

    Hope that helps.
  • 0
    Certified Lead Developer
    I was also unable to reproduce any difference between the two styles of button; but like vinodB suggested, you might need to more tightly control what your saveInto's do.
    I've enhanced your original code in this attached snippet to provide both buttons on-form, and it will allow you to type in a new value that will be assigned to a selected line when either button is pressed. For fun I included code to force selection of only one line at a time, and it clears out the entry box between presses.

    saveInto trouble.sail

  • First create CDT which has fields id, mfr, part, vehicle. Data type of these fields would be Text. Define ri!itemsCart as input which is Array of type CDT. Attached is the code. I clearly see the difference in output between a!buttonWidgetSubmit() and a!buttonWidgetSubmit(). My curiosity is saveInto should work exactly in same way but it is not, why?

    Code.txt

  • 0
    Certified Lead Developer
    The code I attached above is just an enhanced version of yours - I used an RI! of "Any Type" (as opposed to creating a special CDT in my system), but defined it exactly as your suggested inputs, and the two buttons don't seem to behave differently. Did you try the code I attached? It should work just fine with your CDT i assume.