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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Masking of credit card with respective to login credential is not working

(0) ShareShare
ReportReport
Posted on by

hi i have written a simple java script function which which will mask all credit card nos digits except the last four digits for agent login and for any other login(admin/manager) it will display  the credit card

digits(12) as it is or without masking , i am facing two issues here one the it is masking for everyone irrespective of agent or manager login, another the masking is such that the last four digits shows at front and the remaining is shown a complete blank space , for better understanding i am providing both code and screenshot of my implementation. 

// JavaScript source code
function RetrieveLoggedInD365UserSecurityRoles(executionContext) {

var roleName = "Agent";
//will retrieve the credit Card Number from the form
var formContext = executionContext.getFormContext();
var creditCardNum = formContext.getAttribute("cts_creditcardnumber").getValue();
var duplicatecreditCardNum = creditCardNum;
//
//to retrive the global user context from the d365 security profile
var globalContext = Xrm.Utility.getGlobalContext();
var userRoles = globalContext.userSettings.roles;

//using regex it will mask the digits of credit card Numbers
userRoles.forEach(function hasRoleName(item) {
if (item.name == roleName) {
alert("i m in!!")
var replacedCreditCardNum = creditCardNum.replace(/\d(?=\d{4})/g, "x");
formContext.getAttribute("cts_creditcardnumber").setValue(replacedCreditCardNum);
};
if (item.name != rolename) {
formContext.getAttribute("cts_creditcardnumber").setValue(duplicatecreditCardNum);
};

}
);

}

385835.Capture.PNG

it should have shown as "xxxxx-xxxx-0123" and its masking for all

Thank you for helping me out, i tried certain related community post for my implementation and yet i am not getting the desired result . thank you for your time to consider this.

I have the same question (0)
  • Suggested answer
    Saad Kabarousse Profile Picture
    734 on at

    Hello Dear Friend,

    You can try something like this, it gives a form of xxxx-xxxx-xxxx-0256:

    function ShowHideCreditCard(){

    var creditcard =  '2255-5522-2285-0123';

    var parts = creditcard.split('-');

    var invisible_part='xxxx-xxxx-xxxx-';

    var visible_part=parts[parts.length-1];

    alert(invisible_part+visible_part);

    }

  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    I think you can achieve your requirement without writting any code.

    Check below PCF control which does exact same as your requirement.

    pcf.gallery/.../

    Please mark my answer verified if i were helpful

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 108 Super User 2025 Season 2

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans