Update Portal User Name using Deluge?
Hey everyone.
I have a basic intake form that gathers some general information. Our team then has a consultation with the person. If the person wants to move forward, the team pushes a CRM button that adds the user to a creator portal. That process is a CRM function that calls a webhook that calls a Creator function. The process works except it only creates the email and then sets the name and username based on the email prefix. I was hoping there was a way to pass the contacts name during the creation or we could update the portal user after it's created. Is this possible? Below are my codes.
CRM Function
- string button.createCreatorPortalUser(Int accountId)
- {
- try
- {
- // 1. GET THE ACCOUNT RECORD
- accountDetails = zoho.crm.getRecordById("Accounts",accountId);
- // 2. GET THE PRIMARY CONTACT NAME
- primaryContactName = accountDetails.get("Associated_Contacts");
- if(primaryContactName != null)
- {
- // 3. FIND THE CONTACT IN CRM
- searchResults = zoho.crm.searchRecords("Contacts","(Full_Name:equals:" + primaryContactName + ")");
- if(searchResults.size() > 0)
- {
- contactDetails = searchResults.get(0);
- contactEmail = contactDetails.get("Email");
- contactFullName = contactDetails.get("Full_Name");
- if(contactEmail == null || contactEmail == "")
- {
- return "❌ Error: The primary contact '" + contactFullName + "' is missing an email address.";
- }
- // 4. PREPARE JSON BODY
- paramMap = Map();
- paramMap.put("fullName",contactFullName);
- paramMap.put("email",contactEmail);
- paramMap.put("sendInvite","true");
- jsonBody = paramMap.toString();
- // 5. CALL THE CREATOR CUSTOM API
- response = invokeurl
- [
- url :"https://www.zohoapis.com/creator/custom/jaimefurtado2/Add_Portal_User"
- type :POST
- parameters:jsonBody
- headers:{"Content-Type":"application/json"}
- connection:"crm_to_creator"
- ];
- info "Creator Response: " + response;
- // --- Simplified user messages ---
- if(response.get("result") != null)
- {
- statusVal = ifnull(response.get("result").get("status"),"");
- msgVal = ifnull(response.get("result").get("message"),"");
- if(statusVal == "success")
- {
- return "✅ Portal user created successfully. " + msgVal;
- }
- else if(statusVal == "info")
- {
- return "ℹ️ Portal user already exists. " + msgVal;
- }
- else
- {
- return "⚠️ Portal user operation completed, but with warnings: " + msgVal;
- }
- }
- else
- {
- return "⚠️ Unexpected Creator response. Please check logs.";
- }
- }
- else
- {
- return "❌ Error: The primary contact '" + primaryContactName + "' could not be found in the Contacts module.";
- }
- }
- else
- {
- return "❌ Error: The 'Associated_Contacts' field is empty on this Account record.";
- }
- }
- catch (e)
- {
- info "Exception: " + e;
- return "❌ An unexpected system error occurred: " + e;
- }
- }
Creator Function
- map addPortalUser(string fullName, string email, string sendInvite)
- {
- try
- {
- // --- Validate inputs ---
- if(email == null || email.trim() == "")
- {
- return {"status":"error","message":"Email is missing or invalid"};
- }
- if(fullName == null || fullName.trim() == "")
- {
- return {"status":"error","message":"Full name is missing or invalid"};
- }
- // --- Assign to a real profile in THIS portal (case-sensitive) ---
- profileName = "Customer";
- // <-- change if your portal uses a different name
- resp = thisapp.portal.assignUserInProfile(email,profileName);
- info "AssignUser RAW Response: " + resp;
- // New user path
- if(resp != null && resp.containKey("status") && resp.get("status") == "success")
- {
- return {"status":"success","message":"Portal user added and assigned to: " + profileName};
- }
- // Already-exists path
- else if(resp != null && resp.containKey("emailId"))
- {
- existingProfile = profileName;
- if(resp.containKey("profileName"))
- {
- existingProfile = resp.get("profileName");
- }
- return {"status":"info","message":"User already exists. Ensured/retained profile = " + existingProfile};
- }
- // Anything unexpected
- else
- {
- return {"status":"error","message":"Unexpected Creator response: " + resp};
- }
- }
- catch (e)
- {
- info "Exception: " + e;
- return {"status":"error","message":"An unexpected error occurred: " + e};
- }
- }