Looking for help with a search module

I’m building a custom app for my company and having a hard time finding the right documentation. We don’t have a search endpoint, but from what I’ve found this might be possible using an RPC?

We have a list clients endpoint and a get client endpoint.

Ideally the module could iterate through the list of clients and match on the email address. I’m able to get the search module to list all clients, but it’s unclear on the best practice to return only the bundle where the email property is a match for the term.

Looking at the example apps, it looks like most actually have separate modules for List all items and Get individual items, which is definitely possible but looking for a way to combine these 2 steps. Thanks!

If you need assistance on understanding RPC Calls and combining endpoints, don’t hesitate to contact me.

Regards,
Mohamed Jahar
Msquare Automation:gear:

1 Like

Hi Mohamed, thank you for your reply. I was able to figure out the search step, but I was wondering if you had an answer regarding my custom fields RPC.

I have the rpc call to add the custom fields as dynamic mappable params as shown:

[
    {
        "name": "id",
        "type": "text",
        "label": "Client ID",
        "required": true
    },
    {
        "name": "familyName",
        "type": "text",
        "label": "Family Name",
        "required": true
    },
    {
        "name": "givenName",
        "type": "text",
        "label": "Given Name",
        "required": true
    },
	{
        "name": "companyId",
        "type": "text",
        "label": "Company ID",
        "required": false
    },
	"rpc://getCustomFields"
]

And it looks ok in the module:

First question is: when typing in one of the inputs made available by the RPC, it fills all inputs with the same value- how to avoid this?

Second question is: How to add the input values from the generated dynamic fields in the module to the PUT request?

Here is my interface:

[
  {
    "name": "id",
    "type": "text",
    "label": "ID"
  },
  {
    "name": "object",
    "type": "text",
    "label": "Object"
  },
  {
    "name": "created",
    "type": "text",
    "label": "Created"
  },
  {
    "name": "givenName",
    "type": "text",
    "label": "Given Name"
  },
  {
    "name": "familyName",
    "type": "text",
    "label": "Family Name"
  },
  {
    "name": "email",
    "type": "text",
    "label": "Email"
  },
  {
    "name": "companyId",
    "type": "text",
    "label": "Company ID"
  },
  {
    "name": "status",
    "type": "text",
    "label": "Status"
  },
  {
    "name": "inviteUrl",
    "type": "text",
    "label": "Invite Url"
  },
  {
    "name": "customFields",
    "type": "collection",
    "spec": [
      {}
    ],
    "label": "Custom Fields"
  }
]

Here is my communication for now:

{
	"url": "/client",
	"method": "PUT",
	"qs": {},
	"body": {
	    "id": "{{parameters.id}}",
		"givenName": "{{parameters.givenName}}",
		"familyName": "{{lower(parameters.familyName)}}",
		"companyId": "{{parameters.companyId}}"
	},
	"headers": {},
	"response": {
		"output": "{{body}}"
	}
}

If you or anyone else can point me in the right direction, I’ll be ever so grateful! Thank you :slight_smile:

Hey @Allene_Norton ,

Did you manage to fix this?

I can share some solutions here if you still need help with it.

1 Like

@Runcorn I did! Thanks for offering. The solution I found is below:

Mappable parameters:

[
    {
        "name": "id",
        "type": "text",
        "label": "Client ID",
        "required": true
    },
    {
        "name": "familyName",
        "type": "text",
        "label": "Family Name",
        "required": true
    },
    {
        "name": "givenName",
        "type": "text",
        "label": "Given Name",
        "required": true
    },
	{
        "name": "companyId",
        "type": "text",
        "label": "Company ID",
        "required": false
    },
	"rpc://customFields"
]

RPC:

{
	"url": "/custom-fields",
	"method": "GET",
	"qs": {},
	"body": {},
	"headers": {},
	"response": {
        "iterate": "{{dynamicFields(body.items)}}",
        "output": {
            "name": "{{item.id}}",
            "label": "{{item.name}}",
            "type": "{{item.type}}",
			"options": "{{item.options}}",
			"multiple": true,
            "required": false
        }
    }
}

IML:

function dynamicFields(fields) {

    let arr = [];

    if(!fields) return;

    fields.forEach(item => {
        let obj = {};
		let fieldsArr = [];
        let key = item;
        obj.id = key.id;
        obj.name = key.name;
		//obj.type = 'text'
		switch (key.type) {
		case "text":
                obj.type = 'text';
                break;
		case "url":
                obj.type = 'url';
                break;  
		case "phoneNumber":
                obj.type = 'text';
                break;  
		case "multiSelect": //single choice
                obj.type = 'select';
                let optionList = key.options.forEach(option => {
				    let fieldsObj = {};
                    fieldsObj["label"] = option.label;
                    fieldsObj["value"] = option.id;
					fieldsArr.push(fieldsObj)
                });
				obj.options = fieldsArr
                break;
           
            default:
                return;
		}
		//Need to add cases for all types possibly returned from Copilot
        
        arr.push(obj);
    });

    return arr;

}

Had to format the custom fields correctly for parameters and using the RPC/Custom IML solved the issue

1 Like