cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
urklnme
Helper II
Helper II

user object in portals javascript

 

 

<input type="hidden" id="case-user-contact"      value="{{user.id}}" />
<input type="hidden" id="case-user-contact-name" value="{{user.fullname}}" />  
<input type="hidden" id="case-user-account_id"   value="{{user.parentcustomerid.id}}" />
<input type="hidden" id="case-user-account-name" value="{{user.parentcustomerid.name}}" />​

user object in portals javascript

 

A User object is referenced in the javascript for the Create Case web template.

 

Do you know HOW the User object is populated?  It does contain the same fields as Contact.  

Does it affect how the Customer field is set when creating a new Case from the external portal?

Do you have any insights RE: how the Customer is set when submitting a Create Case form? 

 

So for us Contact and Customer records do have same first and last name, but different email addys.

In the Create Case web template, using fetchXML, I find the Customer that matches the Contact based on first and last name.

 

{% fetchxml feed %}
    <fetch version="1.0" mapping="logical" ouptut-format="xml=platform" distinct="false" >  
        <entity name = "account">  
            <attribute name = "accountid" /> 
            <attribute name = "name" />
            <attribute name = "micses_firstname" /> 
            <attribute name = "micses_lastname" /> 
            <attribute name = "emailaddress2" /> 
            <order attribute ='micses_lastname' descending='false' />
            <filter type = "and">
                <condition attribute = "name" operator="eq" value= "{{user.fullname}}" />  
            </filter>
        </entity>
    </fetch>  
{% endfetchxml %}

 

I remove all Customers from the Customer lookup and append the fetchXML Customer.  

 

$("#customerid").empty();

{% for item in feed.results.entities %} {
        let option = document.createElement("option");
        option.value = "{{ item.accountid }}";
        option.innerText = "{{ item.name }}";
        $("#case-user-account_id").val("{{ item.accountid }}");
        $("#case-user-account-name").val("{{ item.name }}");
        $("#customerid").append(option);
    }
{% endfor -%}

 

 

All of the above works.  However, when I submit the Create Case form, the Case created has the original signed in contact fullname in the Customer field.

 

Any help will be appreciated.  I a am single developer maitaining a D365 Help Desk app and an associated External Customer Portal with no Microsoft support contract.

 

7 REPLIES 7
Fubar
Solution Sage
Solution Sage

'user' is the Contact record.  It only exists when someone is logged into the Portal.

'user' is a Liquid (server-side) object the {{....}} are telling the server side to write the values into the HTML/JavaScript, the server then gives it to the browser (client-side) which then renders the HTML/JavaScript.

 

Customer is a complex data type and can accept both Contact and Account records. You appear to be trying to Append() rather than set the values requred. If you look in the Web Template behind the out of the box Create Case you will see the following - you must set as per the first 3 lines

          $("#customerid").val(accountId);
          $("#customerid_name").val(accountName);
          $("#customerid_entityname").val("account");
          

 

 

Whomever created the customized create case for my portal must have wiped out the original web template.

 

Do you know where I might find one?

Hi @urklnme 

 

It is hard to retrieve the web template if is deleted unless it is deactivated. 

 

Hope it helps. 
------------

If you like this post, give it a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users to find it.

 

urklnme
Helper II
Helper II

Yes, I dont have the original web template,  deactivated or otherwise.  The customerid_name field, for example, is not referenced in the web template that I have.

 

Thought someone might have one that they could share with me.

 

 

eugenevanstaden
Helper V
Helper V

@urklnme 

The user object represents the current logged in user (contact record). You can set it on fields, hidden or visible on the form by mixing the Liquid as you have done above.

You can also set the Customer to the current portal user in Form Metadata by adding the Customer field
example:

eugenevanstaden_1-1649196557806.png

 




or on the Form itself

eugenevanstaden_0-1649196511283.png
Or set the Lookup with Javascript by mixing in Liquid, 
$("field").val('{{user.id}}');



 

Well, I must have done something, somewhere to really mess this situation up. 

 

Does any one have the original web template for Create Case or know hwere I can get one?

Fubar
Solution Sage
Solution Sage

How to get the original: Setup a Customer Self-Service Portal in a new instance or in a new Trial.

Helpful resources

Announcements
October Events

Mark Your Calendars

So many events that are happening this month - don't miss out!

MPP IDEAS

Ideas

Discover ideas and concepts from users like you for how to use Power Pages and take your work to the next level.

Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Carousel Community Blog

Check out the Community Blog

Read all about the most recent blogs in the community!

Users online (3,770)