cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Advocate IV
Advocate IV

Custom entity creation not associating with Contact's Account

Hello Power Portal Community,

I hope you can help please.

The process we have is a customer registers and a Contact record is created.
The Contact then goes on to create an Account. They go through a series of "Web Form Steps" to populate the Account. 

The last "Web From Step" is actually another entity called IP. It has a 1:N relationship with the Account. So 1 Account can have many IP records.

The Contact creates an IP record and the "Web Form Steps" end.

 

The issue I'm having is the IP record created is not associating with the Contact's Account. 

What am I missing here? I'm reading on Microsoft Doc's this section "Associate the current portal user with the creation of a record" but not sure what I'm missing. Do I need to create some type of relationship between the Contact and the IP entity?

 

Any help would be greatly appreciated.

Garry

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Solution Sage
Solution Sage

Re: Custom entity creation not associating with Contact's Account

Hi @GarryPope ,

 

There is actually a way to do it without custom JavaScript code, but only for one field (which is applicable for your case). On the Web Form Step where you create an IP go to Entity Reference tab. Select Set Entity Reference On Save to Yes. Then provide details about entity you want to populate into lookup (Account in your case), select proper relationship name between Account and IP and then select Target Lookup Attribute Logical Name (name of the account field on the IP entity). Check Populate Lookup Field checkbox. Then as a source type select the previous step and select the step where you create an account.

And that's it. You can also remove the account field from the creation IP form.

 

Hope this will help.

 

----------------------------------------------------
If you find this post helpful consider marking it as a solution to help others find it.

View solution in original post

7 REPLIES 7
Highlighted
Solution Sage
Solution Sage

Re: Custom entity creation not associating with Contact's Account

 Hi @GarryPope ,

 

Portal will not automatically associate records and provide values unless being specifically told so. On your IP record, you have a lookup to Account (as you say you have 1:N relationship between them). What you need to do is during the creation of IP record to populate that lookup with Account created on the previous step. Usually for the things like that you can use Web Form Metadata, however, it doesn't work like that with lookups. You can either ask your user to select a proper account or more conveniently populate a hidden account field with javascript code. 

 

Place your account field on the form that you are using for your IP creation step. If the account that you created in the previous step is the current user primary account you can use the next code to populate that field:

$(document).ready(
    function () {
        let fieldName = "YOUR_FIELD_NAME_HERE";
        //populate account lookup
        $("#"+fieldname).val('{{user.parentcustomerid.id}}');
        $("#"+fieldname+"_name").val('{{user.parentcustomerid.name}}');
        $("#"+fieldname+"_entityname").val("account");
    }
);

You will need to add this code at Form Options tab in the Custom Javascript section.

 

Hope this will help.

----------------------------------------------------
If you find this post helpful consider marking it as a solution to help others find it.
Highlighted
Advocate IV
Advocate IV

Re: Custom entity creation not associating with Contact's Account

Hello @OOlashyn,

Thanks for the quick reply. It's a shame it has to be done with code. Everything in the portal seems to have to be done with code. 

 

May I ask, which Portal Management record am I adding this to? The "Web Form Step" for when I create the IP record?

If so, I'm unable to get this to work, sorry. I'm adding your code into the "Web Form Step" "Form Options" tab.

Then in the "Custom JavaScript" section I'm pasting your code and changing the place where you said "YOUR_FIELD_NAME_HERE" with my schema name for the Account Lookup field on the IP record.

Yet, when I then create an IP record the Account field doesn't get populated.

 

If I remove your code and un-hide the field, I am able to select the account manually, and when I save the record it is associated correctly. Below is the code. I've blurred out the publisher prefix on my field name.

Javascript.jpg

 

Sorry if I've done something wrong with the code, but I'm not a developer.

 

Thanks again for your help,

Garry

Highlighted
Solution Sage
Solution Sage

Re: Custom entity creation not associating with Contact's Account

Hi @GarryPope ,

 

Sorry for making it a bit unclear. You need to add the field that is not hidden and hide it with code. If you hide the field on the form it will not be rendered on the portal (which for me is really weird behaviour, but MS confirmed to me that it works as it should) and you will not be able to interact with it with code.

 

You can unhide field and add the code to check if it populates everything properly. After that you add hiding part as in code below:

 

$(document).ready(
    function () {
        let fieldName = "YOUR_FIELD_NAME_HERE";
        //populate account lookup
        $("#"+fieldname).val('{{user.parentcustomerid.id}}');
        $("#"+fieldname+"_name").val('{{user.parentcustomerid.name}}');
        $("#"+fieldname+"_entityname").val("account");
        // hide account field
        $("#"+fieldname).trigger("change");
        $("#"+fieldname).closest("td").hide();
    }
);

 

----------------------------------------------------
If you find this post helpful consider marking it as a solution to help others find it.
Highlighted
Advocate IV
Advocate IV

Re: Custom entity creation not associating with Contact's Account

Hello @OOlashyn,

No need to apologise, I think it's me that's making things unclear. Unfortunately, I'm still having problems, sorry.

I added the Account lookup field back onto the IP form and did not hide it.

I then went into the Portal Management model-driven app.

I found my Web Form Step for creating the IP record.

I clicked the Form Options tab.

I scrolled down to the Custom JavaScript section and adding my schema field name where you said I should add it. See below:

Javascript 2.jpg


I then cleared the cache.

I went back to my portal.

Registered as a new user and created a Contact.

I then created an Account.

The other Web Form Steps adds more fields to the Account.

Then finally my last step is where I create the IP record.

When I look at the form, the Account field is still showing. I can't select it, but it's not hidden.

I complete the form.

I go back into the model-driven app, but unfortunately my IP record is still not associated to my Account record.

 

Any other thoughts please? No pressure if not. Potentially I must have set something up incorrectly previously, such as another value on the Web Form Step maybe?

 

Thanks for all your help,

Garry

 

 

Highlighted
Solution Sage
Solution Sage

Re: Custom entity creation not associating with Contact's Account

Hi @GarryPope ,

 

Can you tell me how account that you created is related to the contact that creates it? Code that I presented you will work only if an account that was created is set as a company (parentcustomerid) on contact.

 

 

----------------------------------------------------
If you find this post helpful consider marking it as a solution to help others find it.
Highlighted
Solution Sage
Solution Sage

Re: Custom entity creation not associating with Contact's Account

Hi @GarryPope ,

 

There is actually a way to do it without custom JavaScript code, but only for one field (which is applicable for your case). On the Web Form Step where you create an IP go to Entity Reference tab. Select Set Entity Reference On Save to Yes. Then provide details about entity you want to populate into lookup (Account in your case), select proper relationship name between Account and IP and then select Target Lookup Attribute Logical Name (name of the account field on the IP entity). Check Populate Lookup Field checkbox. Then as a source type select the previous step and select the step where you create an account.

And that's it. You can also remove the account field from the creation IP form.

 

Hope this will help.

 

----------------------------------------------------
If you find this post helpful consider marking it as a solution to help others find it.

View solution in original post

Highlighted
Advocate IV
Advocate IV

Re: Custom entity creation not associating with Contact's Account

Hello @OOlashyn,

YES! That "Entity Reference" option worked perfectly. It's working great now. No code!

Thanks a lot. You've helped with this portal so much.

Thanks for everything, you're the best.

Garry

PS. I'm worried that if you answer any more of my questions on the portal forum, you're going to end up invoicing me! Haha.

Helpful resources

Announcements
secondImage

Demo-Extravaganza 2020

Check out these cool Power Apps & vote on your favorite!

secondImage

Community Highlights

Check out whats happening in Power Apps

secondImage

Community User Group Member Badges

FIll out a quick form to claim your community user group member badge today!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Users online (10,707)