Freshservice react app pass a function to a model

I’m trying to pass a function to a model. I need to get some data back from the model. But it is getting failed. Can you suggest me a better way,

    const handleSelectedRecordClick = (event,selectedItem) =>{

    const handleAccountSearchClick = (event) => {
        props.client.interface.trigger("showModal", {
          title: "Lookup",
          template: "index.html",
          data: {modalID: 'lookup',entity:'accounts', handleSelectedRecordClick : handleSelectedRecordClick}

line in the app js like below

setChild(<model1 client={client}  handleSelectedRecordClick = {handleSelectedRecordClick}/>)

Hi @Nayana_Priyankara, do you mean a “model” or a “modal”? Are you trying to pass a function to a modal? If yes, will this function be executed in the context of the modal?

If so, I don’t believe modal contexts can accept functions. You should pass a JSON-like object in the data property from client.interface.trigger(), then fetch that data in the modal’s context using client.instance.context().

I’m creating a app in ticket sidebar. when a button click it should open a modal. this model have a list of records.(user need to select one of the record) I need to get back the record which user selected back to the ticket sidebar app.

Please see the section on “Send data from a modal to a parent location” in this document: Instance Method.


Thank you for the solution. Pasting below link since in include more details on instance methods.

1 Like

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.