<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.aras.com/community/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Copy to clipboard</title><link>https://www.aras.com/community/f/development/55354/copy-to-clipboard</link><description>Hi, I&amp;#39;m trying to copy data to the clipboard, but, I guess due to limitations, it doesn&amp;#39;t finish copying all of it, the chain is cut off. 
 The idea is, in the tree grid, to make a selection and copy the values ​​of a field determined by me. In practice</description><dc:language>ja-JP</dc:language><generator>Telligent Community 12</generator><item><title>RE: Copy to clipboard</title><link>https://www.aras.com/community/thread/10669?ContentTypeID=1</link><pubDate>Tue, 26 Nov 2024 11:09:56 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:b2f9214b-2aae-4778-906c-58f5349536d2</guid><dc:creator>AngelaIp</dc:creator><description>&lt;p&gt;Where do I start....your code is inefficient by design.&amp;nbsp;&lt;span class="emoticon" data-url="https://www.aras.com/community/cfs-file/__key/system/emoji/1f605.svg" title="Sweat smile"&gt;&amp;#x1f605;&lt;/span&gt;&amp;nbsp;It&amp;acute;s like one of my early works from 8 years ago. Don&amp;acute;t worry, it&amp;acute;s not completely wrong, just some aspects don&amp;acute;t work well if you have a huge amount of data. A lot of Innovator code people write just look like this so it&amp;acute;s super normal. But the forum community can do better&amp;nbsp;&lt;span class="emoticon" data-url="https://www.aras.com/community/cfs-file/__key/system/emoji/1f60e.svg" title="Sunglasses"&gt;&amp;#x1f60e;&lt;/span&gt;&amp;nbsp;:&lt;/p&gt;
&lt;p&gt;TIP: Chat GPT can also give you many tips how to make things more efficient.&lt;/p&gt;
&lt;p&gt;Following code is not tested and can be wrong, but it collects a few things I noticed.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="javascript"&gt;// TIP 1: Why using a switch/case, if you just need to merge an static ItemType name with a static property?
// Create a MAP to match ItemType names to target properties directly
const propertyMap = {
    &amp;quot;MT Ruda&amp;quot;: &amp;quot;mt_rut_nam&amp;quot;,
    &amp;quot;AIT Production Order&amp;quot;: &amp;quot;ait_po_code&amp;quot;,
    // Add more types here
};

let content = [];
for (let i = 0; i &amp;lt; items.getItemCount(); i++) {
    const thisType = this.getType();

    // TIP 2: Get the index item only ONCE to avoid repeating function call of getItemByIndex
    const singleItem = items.getItemByIndex(i);
    const id = singleItem.getProperty(&amp;quot;id&amp;quot;, &amp;quot;&amp;quot;);

    // TIP 3: Declare helper variable HERE, outside of next if block, not &amp;quot;inside&amp;quot; like you have done in the &amp;quot;switch&amp;quot;. In your case you declared the variable inside the switch but used it outside
    let valorTomado = &amp;quot;&amp;quot;;
    
    // Use the map to get the property dynamically
    const propertyKey = propertyMap[thisType];
    
    // Check if key exists, only use it if it&amp;#180;s there
    if (propertyKey) {
        valorTomado = singleItem.getProperty(propertyKey, &amp;quot;&amp;quot;);
    } else {
        // if no entry in map exists do something else
        valorTomado = ....
        // TIP 4: Maybe throw error message to inform people to tell the admin to update the map
        aras.AlertError(&amp;quot;Couldn&amp;#180;t get value for &amp;quot; + thisType + &amp;quot;. Method xyz needs to be updated. Please inform admin.&amp;quot;);
    }
    content.push(valorTomado + &amp;quot;|&amp;quot;);
}


// TIP 5: Ask your favourite AI tool about efficient connectin of very large strings. E.g. instead of concatenating directly, push values into an array and join them into a string afterward. This minimizes the overhead of repeatedly creating new strings. 
let cadena = content.join(&amp;quot;&amp;quot;);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I am not sure if it will really help for your use case. For copy&amp;amp;paste from the grid there is also a CSS solution available. I will need to look it up. It&amp;acute;s not perfect, but maybe sufficient for your use case.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Copy to clipboard</title><link>https://www.aras.com/community/thread/10666?ContentTypeID=1</link><pubDate>Mon, 25 Nov 2024 13:08:45 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:4dfe05db-52f9-49cd-a233-45b7d3129302</guid><dc:creator>FernandoCG</dc:creator><description>&lt;p&gt;Hello, researching and trying and trying, I have realized something curious.&lt;/p&gt;
&lt;p&gt;If I choose 1 or a few records in the grid, the value of the variable is copied to the clipboard, but if many records are chosen, even if the value of the variable is correct, it has the correct data, nothing is copied to the clipboard. That is calculated in the &amp;quot;for&amp;quot;, I don&amp;#39;t know if it is for speed reasons or something like that.&lt;/p&gt;
&lt;p&gt;This is what ChatGPT tells me:&lt;/p&gt;
&lt;p&gt;&amp;quot;The problem seems to be related to the time it takes for the for loop to execute when there are many items (i.e. getItemCount returns a large number). This can cause the browser to temporarily crash or a problem to occur in the code execution flow due to the accumulation of synchronous operations.&lt;/p&gt;
&lt;p&gt;Also, if you try to copy to the clipboard after a long cycle, some browsers or API functions may fail due to runtime restrictions or memory limitations.&amp;quot;&lt;/p&gt;
&lt;p&gt;I could also skip copying the &amp;quot;id&amp;quot;s to the clipboard, for example, and just launch the search automatically, but I don&amp;#39;t know how to force a search in the grid directly.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Copy to clipboard</title><link>https://www.aras.com/community/thread/10659?ContentTypeID=1</link><pubDate>Thu, 21 Nov 2024 16:47:56 GMT</pubDate><guid isPermaLink="false">916d3f7e-8ddc-42f8-8d45-380822f51406:8c0784ad-4237-43e3-9456-51c2c7aa4a67</guid><dc:creator>AngelaIp</dc:creator><description>&lt;p&gt;Ohh the clipboard project! I remember this one! I still use it in a completely different context.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Modern Innovator version have integrated the copy&amp;amp;paste clipboard feature. In general everything above I14 has become very copy&amp;amp;paste friendly.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I wonder why your content is cut.&amp;nbsp;I did a quick test with following code from the Method editor. I worked fine in my environment. It just throws a long string to the buffer. Does this part fail in your environment?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;const buffer = &amp;quot;12312321908098098888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk000000000000000000000000000000000000000000000000000000000000000zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzjmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm,&amp;quot;;

if (window.clipboardData) {
    window.clipboardData.setData(&amp;#39;Text&amp;#39;, buffer);
} else {
    aras.utils.setClipboardData(&amp;#39;Text&amp;#39;, buffer, window);
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>