function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ross Hopkins 8Ross Hopkins 8 

Extract text from text field containing multiple "key:<value>" pairs


I have a field against the Product object, Tags, which contains data such as the following, imported from a thrid-party system:
age:< 12 Months, assetcondition:BRONZE, location:LAVERTON, make:POS SYSTEM, model:3212, power:SIN10AMP, rentalstatus:AVAIL-W, serial:100285954, subcatcode:Swift Assets
When these Product records are created I want to use formulas in a Process Builder Workflow action to extract each "key:<value>" pair, storing all <value>'s in custom fields.

As an example based on the above, one of the formulas would search for "location:" and store "LAVERTON" as the value in a "location__c" field against the Product record. I'd want to do this for age, assetcondition, assetlocation, make etc etc.

I can see lots of examples of using LEFT and MID but haven't been able to create a dynamic enough formula - data in this tags field will vary a lot, so I can't specifiy exact start and end text positions.

Any advice appreciated!

Sampath SuranjiSampath Suranji
You can try apex trigger instead process builder. check below code,
trigger insertCat on yourObjectName(before insert) {

for(yourObjectName c:{
         string nameWithComma= c.Name;
        List<string>strName = nameWithComma.split(',');
        for(string s: strName){
                c.location__c = s.split(':')[1];
                c.age__c = s.split(':')[1];

or You can use apex invokable method inside the process builder to extract data and update relevant fields.
Ross Hopkins 8Ross Hopkins 8
Thank you Sampath. I've not written a trigger before, so whilst I can read that Apex code and understand what is happening, I'm unsure which variables need replacing.

yourObjectName would be replaced with product2 (the standard SF Product object)

If the field containing the tags was called tags__c, would that need only be referenced in line 4:

string nameWithComma= c.tags__c;

and other instances of name/Name are up to me?

Sorry if these are stupid questions!

Sampath SuranjiSampath Suranji
Hi Ross,

Yes, In your scenario, yourObjectName = product2.
If the field containing the tags was called tags__c, then
string nameWithComma= c.tags__c;
Set other variables according to your custom/ system fields.
You can try (