Take the value of a column in sharepoint

0

I am currently doing my diploma work on a SharePoint platform, an instrument I have never used before. The users asked me for a method to compare two text fields RTF, to do it create my own text editor in an iframe and use the DiffMatchPatch library, now the problem is in the implementation, you would have to fill the iframe with the value of the column RTF that contains the information that has to be compared.

searching the internet I found different solutions, but none worked, The last piece of code that I use is the following:

<script>
        $SP().list("1").get({
            fields: "id,corpo",
            where: 'id = "1"'
        },
        function getData(data){
            console.log(data + " data");
            for (var i = 0; i < data.length; i++){
                var frame = document.getElementById("theWYSIWYG");
                frame.contentWindow.document.body.innerText = data[i].getAttribute("corpo");
                console.log(data[i].getAttribute("corpo"));
            }
        });
    </script>

use the content editor to insert my html code, now, how do I take in some way (if possible) the desired field of the current element?

    
asked by Federico Iannarelli 23.08.2018 в 08:59
source

1 answer

0

I found the solution, the condivido in case someone needs:

 SP.SOD.executeFunc('sp.js', 'SP.ClientContext', sharePointReady);
 function sharePointReady() {
        // se carga el el contexto del web
        clientContext = SP.ClientContext.get_current();
        //se elije la lista 
        list = clientContext.get_web().get_lists().getByTitle("Prova Scheda");
        //tomamos el id del campo deseado tramite el url
        var itemId = parseInt(GetUrlKeyValue('ID'));
        item = list.getItemById(itemId);
        //y en fin pedimos la informacion 
        clientContext.load(item);
        clientContext.executeQueryAsync(onRequestSucceeded, onRequestFailed);
    }
    function onRequestSucceeded() {
        corpo = item.get_item('Corpo');
        corpoOr = item.get_item('CorpoOriginale');

        text2 = corpo.replace(/(<([^>]+)>)/ig,"");
        text1 = corpoOr.replace(/(<([^>]+)>)/ig,"");
        text1 = text1.replace("&#160;","");
        text2 = text2.replace("&#160;","");


        var lista1 = dividi(text1);
        var lista2 = dividi(text2);

        $("#ctl00_ctl40_g_d316305f_70e1_4db0_b75a_312430a68b7b_FormControl0_V1_I1_RTC5_RTI1_RT1_newRichText").html(DIFF.diff_prettyHtml(lista1));
        $("#ctl00_ctl40_g_d316305f_70e1_4db0_b75a_312430a68b7b_FormControl0_V1_I1_RTC6_RTI6_RT1_newRichText").html(DIFF.diff_prettyHtml(lista2));
        $("#ctl00_ctl40_g_d316305f_70e1_4db0_b75a_312430a68b7b_FormControl0_V1_I1_RTC6_RTI3_RT1_newRichText").html(DIFF.diff_prettyHtml(lista2));
    }
    function onRequestFailed(sender, args) {
        console.log('Error: ' + args.get_message());
    }
    
answered by 29.08.2018 / 11:29
source