Appian Community
Site
Search
Sign In/Register
Site
Search
User
DISCUSS
LEARN
SUCCESS
SUPPORT
Documentation
AppMarket
More
Cancel
I'm looking for ...
State
Not Answered
Replies
9 replies
Subscribers
7 subscribers
Views
3616 views
Users
0 members are here
Share
More
Cancel
Related Discussions
Home
»
Discussions
»
AI and Rules
Is there a straight forward way to save to an individual field within a multi-va
shamec
over 9 years ago
Is there a straight forward way to save to an individual field within a multi-value CDT variable in SAIL? For example having a customer CDT and trying to populate auto-generated IDs for all the customers as part of a component saveInto, the pseudo-code below doesn’t work:
a!save(local!customers.id, enumerate(length(local!customers)) + 1) - this will save the first target value index(1 in this case) into all customer IDs instead of saving them correctly as 1,2,3...
a!save(local!customers.id[enumerate(length(local!customers)) + 1], enumerate(length(local!customers)) + 1) - still same behavior as above
The problem seems to be that you can specify a list of indices on the left hand side of the a!save function but there doesn't seem to be a way to specify a list of new values on the right hand side - the function is expecting a single value or a rule/function reference. It also looks like the a!save function cannot be placed within looping f...
OriginalPostID-157710
OriginalPostID-157710
Discussion posts and replies are publicly visible
0
shamec
over 9 years ago
...unctions like an apply. I imagine this would be a relatively common problem, anyone with a good supported solution/workaround? I know this can be achieved in the process model but my specific use case requires that I do it in SAIL.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Tim
Certified Lead Developer
over 9 years ago
The trick is to create the array on the right hand side and save into the parent level. You can try using a type constructor as follows:
a!save(local!customers, apply(type!CUSTOMERS_CDT(id: _), 1+enumerate(length(local!customers)))
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
shamec
over 9 years ago
Thanks Tim. I already had this in the back of my mind but I wanted to keep this as a last option. The main issue I've with this is that in addition to populating the ID field I also have to copy over all the other customer data field by field. This becomes an issue whereby whenever new fields are added to the customer CDT, this piece of code will also have to be updated to copy over those new fields and this can be easily missed.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Tim
Certified Lead Developer
over 9 years ago
As an aside can I ask why you're manually creating the customer ids rather than having the rdbms do it?
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Stefan Helzle
A Score Level 3
over 9 years ago
I think there is a plugin to update certain fields of a CDT. This in combination with apply should let you do what you want.
forum.appian.com/.../summary
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
shamec
over 9 years ago
This plugin definitely looks like it might help, specifically the updateCDT function - will try it out and see. Was hoping that I was missing something simple and Appian would support this natively though!
@tim, good point about leaving ID generation to the DB but my use case is actually not about updating customer IDs, I just thought this example would be easier to highlight the issue - I've several complex use cases where a user action on a form results in the need to re-evaluate certain fields in list of entities all of which are multi-value CDTs.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
shamec
over 9 years ago
The plugin works but with some quirks. I was able to make it work by externalizing the code below is a separate rule and calling that rule within an apply function:
/*rule!updateCustomerID*/
updateCDT(ri!customer, {id: ri!id})
/*rule!updateCustomerIDs*/
apply(rule!updateCustomerID(_, _), merge(local!customers, enumerate(length(local!customers)) + 1))
One issue I observed is that the plugin function fails with an exception when trying to clear a field(set to null):
updateCDT(ri!customer, {id: null}) - this will always fail with an exception
updateCDT(ri!customer, {id: ""}) - this seems to work but makes it hard to use this in a dynamic way with a functional that can return null and non-null values at run time
Also this uses Appian dictionaries making it quite difficult to make this code dynamic and generic since this requires being able to dynamically create dictionary keys which is not very well-supported. I was able to do this is a pretty fragile way using a recently introduced json function: jsontodictionary("{"""&tostring(ri!field)&""": "&ri!value&"}")!
Haven't decided which way to go yet but at least I've several options...
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
Stefan Helzle
A Score Level 3
over 9 years ago
The plugin contains the source code, so with a bit of Java knowledge you should be able to adapt it to your needs.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel
0
shamec
over 9 years ago
Yeah I agree, some simple tweaking can make this fit my use case perfectly. Will probably end up doing that.
Cancel
Vote Up
0
Vote Down
Sign in to reply
Verify Answer
Cancel