snippet code to set a model condition based on a JSON string

  • 1
  • Question
  • Updated 2 months ago
  • Answered
I have situation where a field in Salesforce stores the list of id's in JSON format. I need a code to set the condition on a model with the values IN (the list of id's in JSON string). Thanks in advance.
Photo of Shiva Chervirala

Shiva Chervirala

  • 200 Points 100 badge 2x thumb

Posted 3 years ago

  • 1
Photo of Shmuel Kamensky

Shmuel Kamensky, Champion

  • 4,700 Points 4k badge 2x thumb
Hey Shiva,

I haven't tested this code. This is just conceptual. You'll have to adapt it to an actual snippet.

The general idea is that you can do this by using javascript's JSON.parse() function to parse the ids into a javascript list, then populate a multiple value condition with the ids in that list.

So something like this.

modelToFilter = skuid.model.getModel('modelToFilter');
multipleCond = modelToFilter.getCondition('multipleIdCondition');
ids = []
//assuming the field is in the first model. Adjust this to get the correct row
row = skuid.model.getModel('ModelWithStoredIds').getFirstRow();
//get unparsed ids
unparsed = row.fieldWithJson;
//here's where you'll need to do a little messing around. Depending on your JSON schema/structure,
// there may be a different path to your ids. 
//for example if your list is named 'ids' in json, you would accedd the ids through be parsed.ids
//I'm going to assume it's directly in your JSON as the root item
parsed = JSON.parse(unparsed);

return modelToFilter.updateData();
Photo of Praveen Pannala

Praveen Pannala

  • 654 Points 500 badge 2x thumb
Did you find a solution for this? I think it is setting the condition as '=' rather than 'IN' and throwing an exception for me.