How to add Console log in custom button action (No code snippet used)

  • 1
  • Question
  • Updated 7 months ago
  • Answered
Hi Team.

I want to monitor the console log on click the standard save button on skuid page. Could you please let me know how to add console log without javascript code snippet used ?

Thanks
Photo of Rajat Maheshwari

Rajat Maheshwari

  • 420 Points 250 badge 2x thumb

Posted 8 months ago

  • 1
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Can't do this without. The snippet would be very easy though.
Photo of Mark DeSimone

Mark DeSimone, Official Rep

  • 11,050 Points 10k badge 2x thumb
Hi Rajat, I would recommend replacing the standard Save button in your page with one that will run multiple actions. Doing that, you can easily add a snippet to run console.log("Save clicked");  message, or something like this:

var params = arguments[0],
$ = skuid.$;
console.log(params);
Photo of Rajat Maheshwari

Rajat Maheshwari

  • 420 Points 250 badge 2x thumb
Thanks Mark and Vachon, For your prompt response, @Mark, I have create new custom button replaced the standard save button and it works well :)

But here I am getting one trouble, I want to enable/disable the custom button just like the standard save behaviour on row actions basis.

On create new row, I am able to enable the custom button, but how to enable the button on edit row action?

On Rendered options, I am getting below Row property : - 

a. Is New Rocord
b. has Unsaved Changes
c. Is Existing Record in database
d. Is unsaved clone of existing record
e. Is Marked for deletion


Thanks
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Hmmm ... the console log won't provide anything unless it's associated to an action with context. Is the button in a Page Title or Button Set? If Button Set, did you set the model for it?
Photo of Mark DeSimone

Mark DeSimone, Official Rep

  • 11,050 Points 10k badge 2x thumb
Hi Rajat,

I've noticed with console.log() if you log both a string like 'Result' + an object like params together in one log, you'll see the [Object Object].  When you put an object like that into an alert, you're asking to display the whole object and all its layers, but the Alerts aren't built to understand how to do that.

There is probably one item inside params that you're wanting to display, like 'label' or 'result' or 'total success.' You should be able to use something like 

window.alert('Result'+ params.result);

Also, in the snippet you posted, there should not be a period after params. 

I'd try window.alert('Result'+ params); as well, to see if that has an effect. 
Photo of Rajat Maheshwari

Rajat Maheshwari

  • 420 Points 250 badge 2x thumb
Hi Mark,

I tried the same, still It says [Object Object]

Requirement : - 

1. I want to debug the row after save, using alert.

2. Console loge is doing good, It shows me all info related to the newly saved record.

3. But I want to print popup on the page when customer click save button, If it successfully saved OR Id created for the record then print the message "Successfully saved" otherwise print "Error Message" 


On click custom save button, I am performing below action items in these order : - 

1. Save changes in model
2. Run Javascript code snippet (For Console log and alert purpose only)

Thanks
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,436 Points 10k badge 2x thumb
Rajat,

Try this in your snippet:

var params = arguments[0],
$ = skuid.$;
var opp=skuid.$M('Opportunity');
console.log(opp);

alert("opp model-> " + objToString(opp));


function objToString (obj) {
    var str = '';
    for (var p in obj) {
        if (obj.hasOwnProperty(p)) {
            str += p + '::' + obj[p] + '\n';
        }
    }
    return str;
}

See the details here-> https://stackoverflow.com/questions/5612787/converting-an-object-to-a-string

Thanks,

Bill
Photo of Mark DeSimone

Mark DeSimone, Official Rep

  • 11,050 Points 10k badge 2x thumb
Hi Rajat,

I'm interested to see if Bill's suggestion will work for you. I also wanted to offer a declarative way, based on what you described here. When you set up a save button that uses the Save Model Changes action, you can set up an On-Error action, that will display an error message that you can define, or run other actions. There's also a checkbox to rollback changes to all models if the save fails - that could be helpful if you're saving several models at once.

Here's the XML for a simple page showing the on-error action, in case it's helpful:


<skuidpage unsavedchangeswarning="yes" personalizationmode="server" showsidebar="true" useviewportmeta="true" showheader="true">
    <models>
        <model id="Account" limit="1" query="false" createrowifnonefound="true" datasource="salesforce" sobject="Account">
            <fields>
                <field id="Name"/>
                <field id="Description"/>
                <field id="Phone"/>
                <field id="Industry"/>
            </fields>
            <conditions/>
            <actions/>
        </model>
    </models>
    <components>
        <buttonset model="Account" uniqueid="sk-2rdw-289">
            <buttons>
                <button type="multi" label="Save Account" uniqueid="sk-2rdw-294">
                    <actions>
                        <action type="save" rollbackonanyerror="true">
                            <models>
                                <model>Account</model>
                            </models>
                            <onerroractions>
                                <action type="blockUI" message="There was an error saving this record." timeout="3000"/>
                            </onerroractions>
                        </action>
                    </actions>
                </button>
            </buttons>
        </buttonset>
        <basicfieldeditor showheader="true" showsavecancel="false" showerrorsinline="true" model="Account" uniqueid="sk-2rdw-243" mode="read">
            <columns>
                <column width="50%">
                    <sections>
                        <section title="Section A" collapsible="no">
                            <fields>
                                <field uniqueid="sk-2rdw-266" id="Name"/>
                                <field uniqueid="sk-2rdw-267" id="Phone"/>
                            </fields>
                        </section>
                    </sections>
                </column>
                <column width="50%">
                    <sections>
                        <section title="Section B" collapsible="no">
                            <fields>
                                <field uniqueid="sk-2rdw-278" id="Description"/>
                                <field uniqueid="sk-2rdw-279" id="Industry"/>
                            </fields>
                        </section>
                    </sections>
                </column>
            </columns>
        </basicfieldeditor>
    </components>
    <resources>
        <labels/>
        <javascript/>
        <css/>
        <actionsequences uniqueid="sk-2rdw-259"/>
    </resources>
    <styles>
        <styleitem type="background" bgtype="none"/>
    </styles>
</skuidpage>