Need to call widget from another widget.

Allu Gopal1
Giga Guru

Hi,

I am trying to get the widget from another widget. I have tried using the below code, but it is getting as empty only. "sc-variable-summarizer" this is OOB so i dont want to disturb this code.

HTML:

<div>
  <div>
<sp-widget widget="data.details_widget"></sp-widget>
  </div>
</div>

Server script: 

data.details_widget = $sp.getWidget("sc-variable-summarizer", {
        sysId: taskGr.sys_id,
        tableName: getTaskRecord()
    });

I can see that widget is getting called but the variables are not coming for the current record. I called the widget widget is in green color.

find_real_file.png

Please help me on this. Thanks in Advance.

Thanks and Regards,

Allu Gopal.

7 REPLIES 7

Abhijit4
Mega Sage

Did you check if "sc-variable-summarizer" widget needs initial inputs to show data? which is normally sent as options object as example shown below.

options.source_table="sc_2_kb";
    options.target_column="kb_knowledge";
    options.source_column="sc_cat_item";
    options.always_show=false;
    data.template = $sp.getWidget("kb_related_articles",options);

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit
Community Rising Star 2022

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Hi Abhijit,

Thanks for reply, you mean this var tabname= options.table it will fetch dynamically.

Thanks and Regards,

Allu Gopal.

Hi,

If you look at below image which is from Variable Summarizer widget, this widget is trying to get data from Options object.

find_real_file.png

 

This inputs are configured in widget options schema for individual widget instance. When you configure any widget via UI then it has some values which are being used in script via options object. But in your case since you are calling widget via script, those values will be empty so you will have to pass appropriate value for each variable while calling widget with above provided scripting method.

To check which variables are used as input, you can use Ctl+Right Click -> Widget Options Schema as shown below

find_real_file.png

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit
Community Rising Star 2022

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP