Upadte field using validation rule function

Upadte field using validation rule function

Hi, i am trying to format phone field using validation rule, code works in workflow rule (tested), but i need to make this work inside validation rule function, since i already have tons of automation on workflow rule, and i would have problems if this automation run there..

My main problem, is that i dont know how to get DealID in validation rule, in workflow rule, we have "edit arguments" for that.. But in validation rule, we dont have it.. And i need dealID to update field. 

see that line: 
  1. dealId = entityMap.get("id");
This will not work, as it is not returned by crmAPIRequest

Se my code: 
  1. entityMap = crmAPIRequest.toMap().get("record");
  2. decisor = entityMap.get("Whatsapp_Decisor");
  3. dealId = entityMap.get("id");
  4. responseMap = Map();
  5. // Remover todos os caracteres não numéricos do número de telefone
  6. whatsappformatado = decisor.replaceAll("[^0-9]","");
  7. // Verificar o comprimento do número
  8. length = whatsappformatado.length();
  9. // Verificar se o número tem 10 ou 11 dígitos e começa com "55"
  10. if(length == 10 && whatsappformatado.startsWith("55"))
  11. {
  12. // Adicionar "+55" e retornar o número formatado
  13. whatsappformatado = "+55" + whatsappformatado;
  14. }
  15. else if(length == 11 && whatsappformatado.startsWith("55"))
  16. {
  17. // Adicionar "+55" e retornar o número formatado
  18. whatsappformatado = "+55" + whatsappformatado;
  19. }
  20. else if(length >= 12 && length <= 13 && whatsappformatado.startsWith("55"))
  21. {
  22. // Remover o "55" extra e adicionar "+55" e retornar o número formatado
  23. whatsappformatado = "+55" + whatsappformatado.substring(2);
  24. }
  25. else
  26. {
  27. // Se não corresponder a nenhum padrão, assumir que é um número local e adicionar o código do país
  28. whatsappformatado = "+55" + whatsappformatado;
  29. }
  30. // Iniciar a criação do mapa
  31. mapUpdate = Map();
  32. // Definir o valor do campo "Whatsapp_Decisor" no mapa
  33. mapUpdate.put("Whatsapp_Decisor",whatsappformatado);
  34. // Atualizar o registro no Zoho CRM com o novo valor
  35. response = zoho.crm.updateRecord("Deals",dealId,mapUpdate);
  36. // Exibir a resposta da atualização e o número de telefone formatado
  37. responseMap.put("response",response);
  38. responseMap.put("whatsappformatado",whatsappformatado);
  39. return responseMap;
How to solve it? Anyone knows?

Thanks




                            Zoho Desk Resources

                            • Desk Community Learning Series


                            • Digest


                            • Functions


                            • Meetups


                            • Kbase


                            • Resources


                            • Glossary


                            • Desk Marketplace


                            • MVP Corner


                            • Word of the Day



                                Zoho Marketing Automation
                                        • Sticky Posts

                                        • Enrich your CRM data and keep them updated

                                          You spend a lot of your time and efforts in generating quality leads for your business. While generating leads is a challenge in itself, the real deal begins when sales reps try to nurture these leads and convert them as customers. So how equipped is your sales team with information about your leads matters a lot.  For example, you might be using webforms to generate leads and collect customer information from your website. The lesser your webform fields are, the more your sign-ups right? From optimizing
                                        • Zoho CRM Digest - February 2024

                                          We're thrilled to bring you the February digest, packed with exciting product updates and engaging discussions from the Zoho CRM Community. Keep reading to stay in the loop! Product Updates: Zia Enhancements Be it Tasks, Calls, or Meetings, Zia's activity
                                        • Canvas templates can now be shared with different CRM organizations

                                          ----------------------------------------Moderated on 14th February, 2023------------------------------------------- Dear all, This feature is now open for all users in all DCs. To learn more about importing and exporting canvas templates, read our help
                                        • Introducing Zia Presentation in Zoho CRM

                                          ----------------------------------------Moderation 2.0, Date: 22nd March' 24----------------------------------------- The Zia Presentation feature is now available for organizations in both Enterprise and Ultimate editions with 20+ user licenses in the
                                        • Blueprint enhancements - Parallel and multiple transitions, and more

                                          Last modified on Sep 4, 2023: All Zoho CRM users can now access these enhancements. Initially, these features were available only on an early access basis and by request. However, as of August 2, 2023, they have been made available to all users in all


                                        Manage your brands on social media



                                              Zoho TeamInbox Resources

                                                Zoho DataPrep Resources



                                                  Zoho CRM Plus Resources

                                                    Zoho Books Resources


                                                      Zoho Subscriptions Resources

                                                        Zoho Projects Resources


                                                          Zoho Sprints Resources


                                                            Qntrl Resources


                                                              Zoho Creator Resources


                                                                Zoho WorkDrive Resources



                                                                  Zoho Campaigns Resources

                                                                    Zoho CRM Resources

                                                                    • CRM Community Learning Series

                                                                      CRM Community Learning Series


                                                                    • Tips

                                                                      Tips

                                                                    • Functions

                                                                      Functions

                                                                    • Meetups

                                                                      Meetups

                                                                    • Kbase

                                                                      Kbase

                                                                    • Resources

                                                                      Resources

                                                                    • Digest

                                                                      Digest

                                                                    • CRM Marketplace

                                                                      CRM Marketplace

                                                                    • MVP Corner

                                                                      MVP Corner

                                                                    





                                                                    




                                                                        Design. Discuss. Deliver.

                                                                        Create visually engaging stories with Zoho Show.

                                                                        Get Started Now