Best answer

Dynamic fields (not dropdown!) based on parent dynamic dropdown's field value

  • 8 June 2023
  • 1 reply
  • 49 views

Badge +1

Hello

Please note that I have been doing search on my use case, and this:

is not my problem.

On my custom app:

I have a set of projects, and each one have a set of custom fields.

From project to project, these fields are differents. One could have [firstname, lasstname, email]. Other one could be [age, name, f_email] etc.

 

I want to invite the Zap user to select a project => dynamic dropdown, done, works well.

Now, dynamic fields are based upon the id project selected, ie → zappier needs to query some of my API endpoint to know which fields we are talking about. They need to pass the id of the project in the query.

const getProjectContactFields = async (z, bundle) => {
z.console.log('fetching project CL dynamic fields...');
const responsePromise = z.request({
method: 'POST',
url: 'https://docker.didev.ca/webservices/ofc4/projects.ashx?method=Get',
body: JSON.stringify({
idProject: bundle.inputData.idProject
})
});
responsePromise.then(response => {
z.console.log('raw response:', response.data);
z.console.log('project fields: ', response.data.ProjectInfo.ProjectFields);
const inputFields = response.data.ProjectInfo.ProjectFields.map(projectField => ({
key: projectField.Code,
label: projectField.Labels[0].Value,
required: projectField.isRequired,
//Custom metadata for perform script only, may or may not need
isKey: projectField.isKey
}));
return inputFields;
});
// Code: EMail
// Labels[1]
// Culture: en - US
// Value: EMail
// DataType: Email
// Length: 125
// isRequired: true
// isKey: true
}
module.exports = {
key: 'contactMergeDynamic',
noun: 'Add or update contact having dynamic fields',
display: {
label: 'Add Or Update Contact, having dynamic fields',
description: 'Add a new contact to your list or Update an existing one. Fields depend on input project'
},
operation: {
inputFields: [{
key: 'idProject',
label: 'Project identifier',
required: true,
altersDynamicFields: true,
dynamic: 'project.idProject.ProjectName' // special ddl notation: triggerKey.keyFieldName.humanReadableFieldName
},
getProjectContactFields
],
perform: contactMergeDynamic,
//sample: sample
}
}

 The formatting renders badly on my end so just in case: https://smalldev.tools/share-bin/vVDs2HrV

So far, I only get the ddl prompt in the zap edit UI, without the fields appearing.

 

I have trouble linking the function getProjectContactField with its dependent parent idProject. I wonder if this is possible

icon

Best answer by wmarfil 8 June 2023, 21:58

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.

1 reply

Badge +1

Lmao, just a dumb error on my part. was not returning the promise properly. Totally possible therefore.

Anyways I leave the post here as a solution for someone looking to do this pattern if thats cool with you