Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Problems with "while" and "if" in web resource

Posted on by Microsoft Employee

Hello, I have this problem, when I use the sentences "while" and "if" the web resource doesn't work, but when I delete it, it works perfect. Can you help me? What is the problem with mi code?

<html><head>
        <style>
                .myButton {
                    -moz-box-shadow:inset 0px 1px 0px 0px #54a3f7;
                    -webkit-box-shadow:inset 0px 1px 0px 0px #54a3f7;
                    box-shadow:inset 0px 1px 0px 0px #54a3f7;
                    background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #007dc1), color-stop(1, #0061a7));
                    background:-moz-linear-gradient(top, #007dc1 5%, #0061a7 100%);
                    background:-webkit-linear-gradient(top, #007dc1 5%, #0061a7 100%);
                    background:-o-linear-gradient(top, #007dc1 5%, #0061a7 100%);
                    background:-ms-linear-gradient(top, #007dc1 5%, #0061a7 100%);
                    background:linear-gradient(to bottom, #007dc1 5%, #0061a7 100%);
                    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#007dc1', endColorstr='#0061a7',GradientType=0);
                    background-color:#007dc1;
                    -moz-border-radius:3px;
                    -webkit-border-radius:3px;
                    border-radius:3px;
                    border:1px solid #124d77;
                    display:inline-block;
                    cursor:pointer;
                    color:;
                    font-family:Arial;
                    font-size:13px;
                    padding:6px 24px;
                    text-decoration:none;
                    text-shadow:0px 1px 0px #154682;
                }
                .myButton:hover {
                    background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #0061a7), color-stop(1, #007dc1));
                    background:-moz-linear-gradient(top, #0061a7 5%, #007dc1 100%);
                    background:-webkit-linear-gradient(top, #0061a7 5%, #007dc1 100%);
                    background:-o-linear-gradient(top, #0061a7 5%, #007dc1 100%);
                    background:-ms-linear-gradient(top, #0061a7 5%, #007dc1 100%);
                    background:linear-gradient(to bottom, #0061a7 5%, #007dc1 100%);
                    filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#0061a7', endColorstr='#007dc1',GradientType=0);
                    background-color:#0061a7;
                }
                .myButton:active {
                    position:relative;
                    top:1px;
                }
        </style>

<script>
     function GenerarRFC(){
           
                var rfc = window.parent.Xrm.Page.getAttribute("new_rfc").getValue();
                
                    var apellido_paterno = window.parent.Xrm.Page.getAttribute("new_lastname").getValue();
                   
                    var apellido_materno = window.parent.Xrm.Page.getAttribute("new_apellidomaterno").getValue();
                   
                    var primer_nombre = window.parent.Xrm.Page.getAttribute("new_firstname").getValue():
                   
                    var fecha = window.parent.Xrm.Page.getAttribute("new_fechadenacimiento").getValue();
                    
                        var anno = fecha.getFullYear();
                        var mes = fecha.getMonth();
                        var dia = fecha.getDate();    
                   
                    var primera_letra_ap = apellido_paterno.charAt(0).toUpperCase();

                    var encontro = false;
                    var i = 0;

                    while (encontro == false){
                        if ((apellido_paterno.charAt(i).toUpperCase() == "A") ||
                            (apellido_paterno.charAt(i).toUpperCase() == "E") ||
                            (apellido_paterno.charAt(i).toUpperCase() == "I") ||
                            (apellido_paterno.charAt(i).toUpperCase() == "O") ||
                            (apellido_paterno.charAt(i).toUpperCase() == "U")){
                            var primera_vocal = apellido_paterno.charAt(i).toUpperCase();
                            encontro = true;
                        }
                        i++;
                    }

                    var primera_letra_am = apellido_materno.charAt(0).toUpperCase()

                    var primera_letra_nom = primer_nombre.charAt(0).toUpperCase()

                    var palabra_verificar = primera_letra_ap + primera_vocal + primera_letra_am + primera_letra_nom;

                    var palabras_inconvenientes = new Array("BUEI","BUEY","CACA","CACO","CAGA","CAGO","CAKA","CAKO","COGE","COJA","COJE","COJI",
                        "COJO","CULO","FETO","GUEY","JOTO","KACA","KACO","KAGA","KAGO","KOGE","KOJO","KAKA","KULO","MAME","MAMO","MEAR","MEAS",
                        "MEON","MION","MOCO","MULA","PEDA","PEDO","PENE","PUTA","PUTO","QULO","RATA","RUIN");

                    var encontrar = false;
                    var j = 0;
                    while (encontrar == false || encontrar < 41){
                         if(palabras_inconvenientes[j] == palabra_verificar){
                           primera_letra_nom = "X";
                           encontrar = true;
                        }   
                        j++;
                    }

                    var parametro = primera_letra_ap + primera_vocal + primera_letra_am + primera_letra_nom + anno + mes + dia ;

                    window.parent.Xrm.Page.getAttribute("new_rfc").setValue(parametro);  

                }

</script>

    <meta><meta></head>
<body style="word-wrap: break-word;">

<button type="button" class="myButton" onclick="GenerarRFC();">Generar RFC</button>

</body></html>

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Problems with "while" and "if" in web resource

    Thank's you so very much, finally my code works.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Problems with "while" and "if" in web resource

    Thank's  

  • Verified answer
    Andreas Cieslik Profile Picture
    Andreas Cieslik 9,265 on at
    RE: Problems with "while" and "if" in web resource

    var primer_nombre = window.parent.Xrm.Page.getAttribute("new_firstname").getValue():

    should be

    var primer_nombre = window.parent.Xrm.Page.getAttribute("new_firstname").getValue();

    instead : it must be ;

  • Verified answer
    tw0sh3ds Profile Picture
    tw0sh3ds 5,600 on at
    RE: Problems with "while" and "if" in web resource

    Hi,

    This code:

     while (encontrar == false || encontrar < 41){
             if(palabras_inconvenientes[j] == palabra_verificar){
                               primera_letra_nom = "X";
                               encontrar = true;
             }   
             j++;
     }

    makes no sense.

    You are entering while loop and increment j variable. You should check for j in while condition

    so instead of encontrar < 41 should be j < 41 (I did not analyze what the code does but this is a clear bug from technical point of view)

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Problems with "while" and "if" in web resource

    Oh my God!! How I didn't see that!!1 Thank's bro... But still doesn't work

  • Verified answer
    Andreas Cieslik Profile Picture
    Andreas Cieslik 9,265 on at
    RE: Problems with "while" and "if" in web resource

                     var primera_letra_am = apellido_materno.charAt(0).toUpperCase()

                       var primera_letra_nom = primer_nombre.charAt(0).toUpperCase()

    There you miss the semi-colons ;

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans