web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / PCF - Can you load nat...
Power Apps
Unanswered

PCF - Can you load native JS into the controls themselves (i.e. The CRM Xrm api)?

(0) ShareShare
ReportReport
Posted on by

For instance, we would like to build a masking control. That would format a number based on the country the record is associated with. Furthermore we are adding the control to Dynamic CRM. Is there a way the we could load/access the form API (i.e. Xrm.Page.getAttribute("name").getValue()) vs making a call to the database?

I have the same question (0)
  • Hemant Gaur Profile Picture
    on at
    XRM should not be accessed from controls as controls are modular units bound to framework APIs and values.


    For your scenario you can create additional input property to the control and that will surface in the control configuration . Use that to pass in the country value. That way the control is generic and can be configured to any field on any entity and also on canvas apps eventually.
  • Diana Birkelbach Profile Picture
    3,072 Most Valuable Professional on at

    Using the control input property is of course the best solution for this use case, because it keeps it generic.

    But what if the rules for the masking control should be stored somewhere else, allowing the customizer to define their own rules, based on the country? This configuration is not on the form.

    1. One option would be to have a custom entity, where each record represents a country and a masking rule. In this case we can access the database using the Xrm.WebApi since that is stated in the sdk( The problem with that is that we need to install default data, that makes it harder to transport the solution). https://docs.microsoft.com/en-us/powerapps/developer/component-framework/reference/webapi

    2. The second option would be to store the configuration in a webResource (like a JSON config). But it seems to me that the context.resources.getResource method from the sdk (https://docs.microsoft.com/en-us/powerapps/developer/component-framework/reference/resources/getresource) is only designed to load resources from inside the control, that are not accessible to a system customizer. To write our own resource loader (for a normal webResource) we would need some context informations like the clientUrl which I didn't found, so also not possible. 

    3. Or is it recommended wo use another input property with a fixed value, pasting the whole JSON configuration inside?

    Best regards,

    Diana

     

     

  • Hemant Gaur Profile Picture
    on at

    Interesting options Diana, nice writeup. I am thinking for option 1, in order to address limitation of migrating sample data to the custom entity, may be control can have the base rules for the country in the code which control can write to custom entity when loaded first time (using fixed guid). These rules can then be edited by the customizer to fine tune in the org as needed. Something like

    1. Control load very first time in the org, checks the config entity with given guild (webAPi retrive) and sees record not present. Creates the record with base rules present in the control  (TS or XML). 

    2. When the control loads next time it finds the rules and uses them. Also control writes the relevant rule info into local storage using SetState PCF api so that the server call is not needed next time control loads. Uses the cached value to load immediately and sends a call in background to check if there is refreshed data. 

    3 Control can also surface the link to config entity if there is user specific customizations need, like toggle to  address validaor by pressing ctrl + Y. User might be in a fixed timezone but does not mean that the addresses he is entering are same country. Toggle at the top and show hide controls default vs custom is another option. 

  • Diana Birkelbach Profile Picture
    3,072 Most Valuable Professional on at

    Verry interesting ideas Hemant. Thank you for sharing Smiley Happy

    You've mentioned  saving in local storage using SetState PCF api . Unfortunatelly i didn't found this feature. 

    Is the documentation refering this still to be done, or am I just missing it? Or maybe there is an example for that?

    Best regards,

    Diana

  • Community Power Platform Member Profile Picture
    on at

    Are the input controls static? If so, I do not think this would work as our most common use case would be creating a new lead/contact. And in that scenario, we would not know the country they belong to until it was populated (i.e. when the form loaded we would not know the country as it is blank).

  • Hemant Gaur Profile Picture
    on at
    Yes we have sample and documentation -

    https://docs.microsoft.com/en-us/powerapps/developer/component-framework/sample-controls/control-state-api


    Hemant
  • Community Power Platform Member Profile Picture
    on at

    Hemant, unless I am missing something. This will only load files that I have pre-defined. In this scenario, the Xrm API would not be available until run time, as it is full managed by the application itself.

  • Hemant Gaur Profile Picture
    on at
    XRM should not be accessed from the control. Only framework APIs.
  • Community Power Platform Member Profile Picture
    on at

    It sounds like the PCF is not the right fit for a scenario like this.

  • Hemant Gaur Profile Picture
    on at

    @Anonymous wrote:

    It sounds like the PCF is not the right fit for a scenario like this.


    Lets try one more time. Can you explain what is the end user expereince expected, possibly with some mock screens if that helps. We can then see whats the best fit. 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard