Best answer

How to convert custom fields array into the key value pair?

  • 2 September 2019
  • 13 replies

Userlevel 1

I have a trigger, which returning ar array of custom fields. each element of the array have a two keys FIELD_VALUE and FIELD_NAME.

When I am mapping these fields in an action there are only two field available :

  1. FIELD VALUES ==> comma(,) separated values of all custom fields key FIELD_VALUE, similarly
  2. FIELD NAMES ==> comma(,) separated values of all custom fields key FIELD_NAMES

I want to convert all of the fields in a key:value pair. So the value of FIELD_NAME will be a key and value of FIELD_VALUE will be a value.

I have tried to use code by zapier but it is not working as expected:

Here is my JS code:

var names = (inputData.names).split(',');

var values = ((inputData.values).toString()).split(',');

var obj = names.reduce((obj, key, index) => ({ ...obj, [key]: values[index] }), {});

Screenshot from 2019-09-02 16-51-50.pngThe problem is null values, Zapier removing null values from comma (,) separated string.


Best answer by Openside 3 September 2019, 00:32

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

13 replies

Userlevel 5
Badge +3

could you loop through and convert nulls to empty strings ("") ? would that change behavior?

Userlevel 1

Yes we can but the problem is inputData.values missing null values. null values are not available at In inputData.values

Userlevel 5
Badge +3

ah, gatcha. yeah not sure if that is fixable at that point. I think it needs to be fixed prior to the trigger (i.e. at the source). zapier really needs to improve how it treats line items

Userlevel 7
Badge +9

@codetycon and @Openside do you have suggestions on what specifically Zapier can change to improve line item handling? How would you prefer to have this function? I'd really love to help flush this out with y'all so I can pass this along to the product team responsible for improvements here. Let me know!

Userlevel 1

@jesse Can we have a raw json too along with the current response from trigger? if raw json is available then we can manipulate it accordingly using code by Zapier and can use in the next actions.

Userlevel 3
Badge +2

@codetycon @jesse I think it's a good way to have a RAW JSON because sometimes we need to manipulate trigger's response before passing it to the action. In case of custom fields, line items, multiple addresses [Work,Home,Mobile] we need to apply some formulas or logic before using them in a action. I'm not sure if it is an optimized solution or not, #Zapier development team can suggest an better way to handle this.

Userlevel 5
Badge +3

Userlevel 7
Badge +9

@codetycon and @sudesh gotcha, so you would like to have raw JSON available for ANY trigger then? Just trying to think through this a bit as we're trying to strike a balance of giving technical tools to advanced users but not to scare off beginners, either. Any recommendations on how we might be able to strike the balance there?

Userlevel 1

Hey folks, Brian Cooksey here from the Zapier engineering team. I thought I'd chime in to give a little more context. Regarding the raw JSON, that's an interesting one. Awhile back we had thought about offering something like {{__output_raw}} as a way to say "give me everything from this step in the Zap." Would that cover the usecase you have in mind where you want to parse that with code?

As for the line items, that one has a complicated history. Our platform has gone through several iterations. If you are trying to build a Zap using an app built on the original platform, then yes, you get unwanted behavior with commas. The reason we can't simply fix that one is that it would be a major breaking change to lots of apps and lots of pre-existing Zaps.

The good news is that as the Platform has evolved, we've fixed this oversight with line items. Thus, if you go create a new app today, the structure returned from the trigger should be preserved, commas and all, so that any Action receiving the data will have it as intended.

Userlevel 5
Badge +3

good to know @cooksey . thanks. and yes, a {{__output_raw}} would be very useful, but would always want it for each step. like {{__output_raw_step4}} - this would be helpful when sending data to a webhook to avoid having to create all the postfields in the webhook.

Userlevel 2

@cooksey I encountered in the same issue when getting a matter details from Practice partner,

I notice you mention that you fixed this issue, and I need to create new app, can you elaborate what do you mean by creating new app?

I created a new zap with Practice partner step that find a matter, but I still see all the custom fields in one long line with comma separator.

I cant match each name to the value since I have "null"s in it.

Any help will be appreciated.

Userlevel 7
Badge +10

@Rotem what @cooksey was talking about was creating an app on the Zapier developer platform. The issues needs to be corrected before it gets to the Zap level.

If you don't have that as an option (I'm guessing you mean practice panther which does have an API so it is possible for you to build a private app on the Zapier platform that uses the new method of dealing with commas.)

However, @cooksey I'm not so sure the null value problem has been fixed as shown here: this is with my own private app for Quickbooks and it's still ignoring null values in line items. I'm not sure this is a comma issue. And I assume it's the same thing @Rotem has experienced.

Userlevel 1

@Rotem - @PaulKortman is correct, I meant creating a new app on our Platform, which you could then build Zaps with. If you didn't create the original Practice Partner, though, that's probably not feasible as you would have to re-integrate to their API yourself. You'll likely have to wait until that partner upgrades.

@PaulKortman regarding that other question, I'll follow up there.