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

    Access your files securely from anywhere

        Zoho Developer Community




                                  Zoho Desk Resources

                                  • Desk Community Learning Series


                                  • Digest


                                  • Functions


                                  • Meetups


                                  • Kbase


                                  • Resources


                                  • Glossary


                                  • Desk Marketplace


                                  • MVP Corner


                                  • Word of the Day



                                      Zoho Marketing Automation


                                              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 Campaigns Resources


                                                                          Zoho CRM Resources

                                                                          • CRM Community Learning Series

                                                                            CRM Community Learning Series


                                                                          • Kaizen

                                                                            Kaizen

                                                                          • 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