Update Portal User Name using Deluge?

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
  1. string button.createCreatorPortalUser(Int accountId)
  2. {
  3. try 
  4. {
  5. // 1. GET THE ACCOUNT RECORD
  6. accountDetails = zoho.crm.getRecordById("Accounts",accountId);
  7. // 2. GET THE PRIMARY CONTACT NAME
  8. primaryContactName = accountDetails.get("Associated_Contacts");
  9. if(primaryContactName != null)
  10. {
  11. // 3. FIND THE CONTACT IN CRM
  12. searchResults = zoho.crm.searchRecords("Contacts","(Full_Name:equals:" + primaryContactName + ")");
  13. if(searchResults.size() > 0)
  14. {
  15. contactDetails = searchResults.get(0);
  16. contactEmail = contactDetails.get("Email");
  17. contactFullName = contactDetails.get("Full_Name");
  18. if(contactEmail == null || contactEmail == "")
  19. {
  20. return "❌ Error: The primary contact '" + contactFullName + "' is missing an email address.";
  21. }
  22. // 4. PREPARE JSON BODY
  23. paramMap = Map();
  24. paramMap.put("fullName",contactFullName);
  25. paramMap.put("email",contactEmail);
  26. paramMap.put("sendInvite","true");
  27. jsonBody = paramMap.toString();
  28. // 5. CALL THE CREATOR CUSTOM API
  29. response = invokeurl
  30. [
  31. url :"https://www.zohoapis.com/creator/custom/jaimefurtado2/Add_Portal_User"
  32. type :POST
  33. parameters:jsonBody
  34. headers:{"Content-Type":"application/json"}
  35. connection:"crm_to_creator"
  36. ];
  37. info "Creator Response: " + response;
  38. // --- Simplified user messages ---
  39. if(response.get("result") != null)
  40. {
  41. statusVal = ifnull(response.get("result").get("status"),"");
  42. msgVal = ifnull(response.get("result").get("message"),"");
  43. if(statusVal == "success")
  44. {
  45. return "✅ Portal user created successfully. " + msgVal;
  46. }
  47. else if(statusVal == "info")
  48. {
  49. return "ℹ️ Portal user already exists. " + msgVal;
  50. }
  51. else
  52. {
  53. return "⚠️ Portal user operation completed, but with warnings: " + msgVal;
  54. }
  55. }
  56. else
  57. {
  58. return "⚠️ Unexpected Creator response. Please check logs.";
  59. }
  60. }
  61. else
  62. {
  63. return "❌ Error: The primary contact '" + primaryContactName + "' could not be found in the Contacts module.";
  64. }
  65. }
  66. else
  67. {
  68. return "❌ Error: The 'Associated_Contacts' field is empty on this Account record.";
  69. }
  70. }
  71. catch (e)
  72. {
  73. info "Exception: " + e;
  74. return "❌ An unexpected system error occurred: " + e;
  75. }
  76. }

Creator Function
  1. map addPortalUser(string fullName, string email, string sendInvite)
  2. {
  3. try 
  4. {
  5. // --- Validate inputs ---
  6. if(email == null || email.trim() == "")
  7. {
  8. return {"status":"error","message":"Email is missing or invalid"};
  9. }
  10. if(fullName == null || fullName.trim() == "")
  11. {
  12. return {"status":"error","message":"Full name is missing or invalid"};
  13. }
  14. // --- Assign to a real profile in THIS portal (case-sensitive) ---
  15. profileName = "Customer";
  16. // <-- change if your portal uses a different name
  17. resp = thisapp.portal.assignUserInProfile(email,profileName);
  18. info "AssignUser RAW Response: " + resp;
  19. // New user path
  20. if(resp != null && resp.containKey("status") && resp.get("status") == "success")
  21. {
  22. return {"status":"success","message":"Portal user added and assigned to: " + profileName};
  23. }
  24. // Already-exists path
  25. else if(resp != null && resp.containKey("emailId"))
  26. {
  27. existingProfile = profileName;
  28. if(resp.containKey("profileName"))
  29. {
  30. existingProfile = resp.get("profileName");
  31. }
  32. return {"status":"info","message":"User already exists. Ensured/retained profile = " + existingProfile};
  33. }
  34. // Anything unexpected
  35. else
  36. {
  37. return {"status":"error","message":"Unexpected Creator response: " + resp};
  38. }
  39. }
  40. catch (e)
  41. {
  42. info "Exception: " + e;
  43. return {"status":"error","message":"An unexpected error occurred: " + e};
  44. }
  45. }