Selected value is not highlighted.

Selected value is not highlighted.

Workflow Automation ExpertWorkflow Automation Expert Posts: 14Questions: 4Answers: 0
edited August 22 in Free community support

When I edit a record the select field selected value is not highlighted. The options populate fine. I can select an option and save. Record is written correctly to DB and JSON returned(see below) successfully.

I understand for this to work the data table must match the editor field. I have attempted to do that(see below) without success. Please advise what I'm doing wrong.

Editor Field

    {
                  label: 'Email Campaign:',
                  name:   'prospect.emailcampaign',
                  type: 'datatable',
                  optionsPair: {
                          label: 'name',
                          value: 'id'
                  },
                  config: {
                      columns: [
                          {
                              title: 'Name',
                              data: 'name'
                          }
                      ]
                  }
              }

Data Table Column

{ data: 'emailcampaign.name', editField: 'prospect.emailcampaign' },

Returned JSON payload on Edit

                {
                  "data": [
                    {
                      "id": "f69a45aa-ebcb-4094-bebc-f59ffad47ee7",
                      "prospect": {
                        "linkedin": "https://www.linkedin.com/in/xxxxxxxxxxxxxxxxxxx2268/",
                        "email": "hello@xxxxxxxxxxxxxxpert",
                        "lastname": "Marunda",
                        "industry": "Information Communication Technology",
                        "city": "Harare",
                        "title": "Mr.",
                        "region": "Mashonaland",
                        "firstname": "Arnold Tonderai",
                        "avatar": "https:/xxxxxxxxxxxx/4c69647b096b7d00f350ec2b054e8082/290900378/profile.jpeg?s=",
                        "mobiletelephone": "xxxxxxxxxxx",
                        "website": "https://arnoldxxxxxxxxxxxxxxpert",
                        "fixedtelephone": "",
                        "jobtitle": "Workflow Automation Expert",
                        "country": "Zimbabwe",
                        "company": "Edenpoint Projects"
                      },
                      "emailcampaign": {
                        "name": null,
                        "id": null
                      },
                      "socialcampaign": {
                        "name": "No Footprint-S2C7-Linkedin",
                        "id": "07e6c08a-e052-486c-b049-6189dbf3d13a"
                      }
                    }
                  ],
                  "options": {
                    "prospect.emailcampaign": [
                      {
                        "name": "Footprint-S1C7",
                        "id": "758a4c1f-4630-4a09-9234-0f7a4f3c10ea"
                      },
                      {
                        "name": "Non-Footprint-S2C7",
                        "id": "a3fca475-0677-474a-ad65-46ae5408afd1"
                      }
                    ],
                    "prospect.socialcampaign": [
                      {
                        "name": "Footprint-S1C7-Linkedin",
                        "id": "34b4d4ce-4f60-403c-a401-c834592e79ee"
                      },
                      {
                        "name": "No Footprint-S2C7-Linkedin",
                        "id": "07e6c08a-e052-486c-b049-6189dbf3d13a"
                      }
                    ]
                  },
                  "files": []
                } 

Screenshot of issue

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,597Questions: 1Answers: 10,485 Site admin

    Hi,

    The way Editor is set up there is that it is being told to look for data in prospect.emailcampaign. However, there isn't a emailcampaign field in the prospect object. There is a emailcampaign.id, but I'd be surprised if you wanted to edit that!

    Can you show me your controller code - specifically I'm looking for information about the join that is used to tell the prospect row, what email or social campaign it should link to. Is that a column in the prospect table?

    Allan

  • Workflow Automation ExpertWorkflow Automation Expert Posts: 14Questions: 4Answers: 0

    Hi Allan,

    My controller code is in Python on the Anvil.works runtime server as follows...

    Build JSON payload to be returned to Editor

    def api_return_prospect_s(emailcampaigns, socialcampaigns, prospects):
        _emailcampaigns = [
          {
          "name": f"{campaign['name']}-{campaign['segment']}{campaign['cycle']}",
          "id": campaign['id']
          }
        for campaign in emailcampaigns or []]
    
        _socialcampaigns = [
          {
          "name": f"{campaign['name']}-{campaign['segment']}{campaign['cycle']}-{campaign['network']['name']}",
          "id": campaign['id']
          }
        for campaign in socialcampaigns or []]
     
        _prospects = [
          {
          "id": prospect['id'],
          "prospect": {
            "avatar": prospect['avatar'].url if prospect['avatar'] else None,
            "title": prospect['title'],
            "firstname": prospect['firstname'],
            "lastname": prospect['lastname'],
            "jobtitle": prospect['jobtitle'],
            "linkedin": prospect['linkedin'],
            "email": prospect['email'],
            "industry": prospect['industry'],
            "company": prospect['company'],
            "website": prospect['website'],
            "fixedtelephone": prospect['fixedtelephone'],
            "mobiletelephone": prospect['mobiletelephone'],
            "city": prospect['city'],
            "region": prospect['region'],
            "country": prospect['country']
            },
            "emailcampaign": {
              "name": f"{prospect['email_campaign']['name']}-{prospect['email_campaign']['segment']}{prospect['email_campaign']['cycle']}" if prospect['email_campaign'] else None,
              "id": prospect['email_campaign']['id']  if prospect['email_campaign'] else None
            },
            "socialcampaign": {
              "name": f"{prospect['social_campaign']['name']}-{prospect['social_campaign']['segment']}{prospect['social_campaign']['cycle']}-{prospect['social_campaign']['network']['name']}" if prospect['social_campaign'] else None,
            "id": prospect['social_campaign']['id'] if prospect['social_campaign'] else None
            }
          } 
        for prospect in prospects]
    
        payload = {
          "data": _prospects,
          "options": {
              "prospect.emailcampaign": _emailcampaigns, 
              "prospect.socialcampaign": _socialcampaigns
          },
          "files": []
          }   
    
        return payload 
    

    Update Prospect row with formdata paramatersfrom Editor

    prospect = app_tables.prospects.get(id=params['id'])
          email_campaign = app_tables.campaigns_email.get(id=params[f"data[{params['id']}][prospect][emailcampaign]"]) if params[f"data[{params['id']}][prospect][emailcampaign]"] else None
          social_campaign = app_tables.campaigns_social.get(id=params[f"data[{params['id']}][prospect][socialcampaign]"]) if params[f"data[{params['id']}][prospect][socialcampaign]"] else None
          prospect.update(
                updated = datetime.datetime.now(),
                title = titlecase(params[f"data[{params['id']}][prospect][title]"]),
                firstname = titlecase(params[f"data[{params['id']}][prospect][firstname]"]),
                lastname = titlecase(params[f"data[{params['id']}][prospect][lastname]"]),
                jobtitle = titlecase(params[f"data[{params['id']}][prospect][jobtitle]"]),
                industry = titlecase(params[f"data[{params['id']}][prospect][industry]"]),
                company = titlecase(params[f"data[{params['id']}][prospect][company]"]),
                website = params[f"data[{params['id']}][prospect][website]"],
                linkedin = params[f"data[{params['id']}][prospect][linkedin]"],
                email = params[f"data[{params['id']}][prospect][email]"],
                fixedtelephone = params[f"data[{params['id']}][prospect][fixedtelephone]"],
                mobiletelephone = params[f"data[{params['id']}][prospect][mobiletelephone]"],
                city = titlecase(params[f"data[{params['id']}][prospect][city]"]),
                region = titlecase(params[f"data[{params['id']}][prospect][region]"]),
                country = titlecase(params[f"data[{params['id']}][prospect][country]"]),
                email_campaign = email_campaign,
                social_campaign = social_campaign
                )
          json = api_return_prospect_s(      
            app_tables.campaigns_email.search(id=email_campaign['id']) if email_campaign else None,
            app_tables.campaigns_social.search(id=social_campaign['id']) if social_campaign else None,
            app_tables.prospects.search(id=prospect['id'])
          )
          return anvil.server.HttpResponse(200, json )
    
  • allanallan Posts: 63,597Questions: 1Answers: 10,485 Site admin

    Apologies, I'm not a Python developer. I presume this has an SQL backend - so perhaps we can discuss in those terms. What links a prospect to an email campaign? Is there anemail_campaign column in the prospects table?

    Allan

  • Workflow Automation ExpertWorkflow Automation Expert Posts: 14Questions: 4Answers: 0
    edited August 22

    Yes, email_campaign and social_campaign are fields in the SQL DB with a one-to-one join relationship with respective tables.

  • Workflow Automation ExpertWorkflow Automation Expert Posts: 14Questions: 4Answers: 0

    Not quite following your investigation into the data model. I thought Editor would just use the JSON file presented to it?

  • allanallan Posts: 63,597Questions: 1Answers: 10,485 Site admin
    Answer ✓

    Okay, so there is a email_campaign column in the prospect table? And that in turns holds an id that relates to emailcampaign.id?

    That being the case, I would expect to see a email_campaign value in the prospect object, since that is the value that you want to edit to update the reference. You want emailcampaign.name to display in the DataTable, that's fine, but when you actually update the record to point at a different email campaign then you need to change the value of prospect.email_campaign.

    If you look at this example you'll see that there is a users.site value, which points to the id in the sites table. I use sites.name to display in the DataTable, but when a user's site changes, it writes the site id to users.site.

    Allan

  • Workflow Automation ExpertWorkflow Automation Expert Posts: 14Questions: 4Answers: 0

    Hi Allan,

    Thank you for looking at this in detail. Much appreciated.

    Have followed your instruction and it works. The example was very useful.

    regards,

    Arnold

  • allanallan Posts: 63,597Questions: 1Answers: 10,485 Site admin

    Awesome - great to hear you've got it working :)

    Allan

Sign In or Register to comment.