edit rows into a collection

216 views
Skip to first unread message

ingen...@bammtech.cl

unread,
Mar 13, 2015, 11:43:21 AM3/13/15
to suppor...@runmyprocess.com
I use this code ( ${import_objects("file_id","collection_name", ",", "true/false")} ) to import my google spreadsheet into a collection (in csv format obviusly) and i was following this example http://docs.runmyprocess.com/Developer_Guide/Collection/Collections_BackOffice to edit and delete items with a report widget, but this only works with the new rows that I add into de collection. I guess that's because the code that adds an unique id and based on that you can edit and delete rows. if I'm right, is there any way to give this unique id to the rows that already has the collection?

Pankaj Kumar

unread,
Mar 14, 2015, 6:48:47 AM3/14/15
to suppor...@runmyprocess.com, ingen...@bammtech.cl
Hi,

Thank you for contacting Fujitsu RunMyProcess Support. 

Yes, for this you need to update the collection object. you can use "updateCallback" method for this in java script.
id_collection.updateCallback(pattern,newobject,callbackSuccess,callbackFailure)
Here, "newobject" Object will replace the first matching record in the collection. you can add the id field in the new object and rest of the property as of the collection object.

Please refer to the following links:-
Thanks & Regards,
Pankaj Kumar


On Fri, Mar 13, 2015 at 9:13 PM, <ingen...@bammtech.cl> wrote:
I use this code  ( ${import_objects("file_id","collection_name", ",", "true/false")} ) to import my google spreadsheet into a collection (in csv format obviusly) and i was following this example http://docs.runmyprocess.com/Developer_Guide/Collection/Collections_BackOffice  to edit and delete items with a report widget, but this only works with the new rows that I add into de collection. I guess that's because the code that adds an unique id and based on that you can edit and delete rows. if I'm right, is there any way to give this unique id to the rows that already has the collection?

--
Fujitsu - RunMyProcess
---
You received this message because you are subscribed to the Google Groups "RunMyProcess Support Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to supportforum...@runmyprocess.com.
To post to this group, send email to suppor...@runmyprocess.com.
Visit this group at http://groups.google.com/a/runmyprocess.com/group/supportforum/.
To view this discussion on the web visit https://groups.google.com/a/runmyprocess.com/d/msgid/supportforum/8728736c-76c0-4ee6-9afc-de95e7d59368%40runmyprocess.com.
For more options, visit https://groups.google.com/a/runmyprocess.com/d/optout.

Pankaj Kumar

unread,
Mar 17, 2015, 1:12:49 AM3/17/15
to suppor...@runmyprocess.com

---------- Forwarded message ----------
From: Grupo Ingenieria <ingen...@bammtech.cl>
Date: Mon, Mar 16, 2015 at 7:55 PM
Subject: Re: [supportforum:6552] edit rows into a collection
To: Pankaj Kumar <pku...@runmyprocess.com>


Thanks for your help. I saw the documentation and I have a little problem. As you say, I made a test with one row and i updated the record, the problem is that I have more than 200 rows and it takes a lot of time to do that with all the rows. Also, in the back office example, it uses a function to add an unique id and with that I can edit and delete rows.

This is the script that I use to update

function update_ok(result) {
alert("ok " + JSON.stringify(result));
}

function uniqueId(){
    var idstr=String.fromCharCode(Math.floor((Math.random()*25)+65));
    do {               
        // between numbers and characters (48 is 0 and 90 is Z (42-48 = 90)
        var ascicode=Math.floor((Math.random()*42)+48);
        if (ascicode<58 || ascicode>64){
            // exclude all chars between : (58) and @ (64)
            idstr+=String.fromCharCode(ascicode);   
        }               
    } while (idstr.length<32);

    return (idstr);
}

function update_ko(result) {
alert("ko " + JSON.stringify(result));
}

var my_pattern = {};
my_pattern.TYPE = "HW";

var my_object = {};
my_object.codigo = "444-555";
my_object.codigo = uniqueId();

col_paloalto2.updateMultiCallback(my_pattern,{$set:my_object},update_ok,update_ko);


As you can see, my pattern is "HW" but with my object as "444-555" all the hw type has the same code. Do you know any way to give all the rows with pattern "HW" a different unique id an then edit or delete them?


Pankaj Kumar

unread,
Mar 17, 2015, 5:01:21 AM3/17/15
to suppor...@runmyprocess.com, Grupo Ingenieria
Hi,

my pattern is "HW" but with my object as "444-555" all the hw type has the same code. Do you know any way to give all the rows with pattern "HW" a different unique id an then edit or delete them

Response: 
If you want to update multiple objects ie 200 than java script is not the best way to do it.
you can use free marker API to update objects.

I am sharing you a sample Free marker script to update all the objects in the collection and add an new property "id", in all the objects in the collection. here I have assume, previously "id" property not exist in object, so it will add this property in every object. if this property exist in your objects, you can give it another name, it will work as a unique id for each object.

<#assign data = list_objects({"$query":{},"$orderby":{"name":-1}},"testColl")>
<#assign counter = 0>
<#assign items = []>
<#list data as i>
<#assign counter = counter + 1>
<#assign myObject=P_json_accumulate( i, "id", counter)>
<#assign items = items + [myObject]>
</#list>
<#assign array1 = save_object(items,"testColl")>
${array1}

Note:- here "testColl" is the name of the collection.

If you want to do it in java script, then one way to achieve this,

load all the objects of the collection in java script, modify each object using the for loop, and update it back in for loop.

if your pattern is giving you multiple record, add more property in the search criteria to give you 1 object, if you are not able to get a single object by adding more property in search pattern, it means you have duplicate objects with same data, you need to remove duplicate objects to normalize your collection.



Thanks & Regards,
Pankaj Kumar


Reply all
Reply to author
Forward
0 new messages