Import Set warning logs

Rashmi Rao
Tera Expert

We have a transform map for sccm to fetch and map the collection members with two field maps both being coalesce, one is Device and another one called collection with choice action as "reject". The import set table is pulling lot of records. below are the field map script for both. This transforms map is generating import logs called "More than one target records exists for target table u_m2m_sccm_collection_member with query u_cmdb_sccm_collection=716327938798123"

 

Collection:field map script

 

answer = (function transformEntry(source) {

    if (!source.u_collectionid)
        return "";

    var sourceName = "SCCM";
    if (source.sys_import_set.data_source.name && source.sys_import_set.data_source.name.indexOf(" - ") != -1)
        sourceName += "-" + source.sys_import_set.data_source.name.replace(/^.* - /g, "");

    var sys_object_source = new GlideRecord("sys_object_source");
    sys_object_source.addQuery("name", sourceName);
    sys_object_source.addQuery("id", source.u_collectionid);
    sys_object_source.addQuery("target_table", "u_cmdb_sccm_collection");
    sys_object_source.addNotNullQuery("target_sys_id");
    sys_object_source.query();
    while (sys_object_source.next()) {
        gs.log("sysid" + sys_object_source.target_sys_id);
        var cmdb_ci = new GlideRecord(sys_object_source.target_table);
        if (cmdb_ci.get(sys_object_source.target_sys_id))
            return cmdb_ci.sys_id + "";
            log.warn("collection first loop"+ cmdb_ci.sys_id);
    }

    if (source.u_sitecode) {
        var u_cmdb_sccm_collection = new GlideRecord("u_cmdb_sccm_collection");
        u_cmdb_sccm_collection.addQuery("u_sccm_site.u_site_code", source.u_sitecode);
        u_cmdb_sccm_collection.addQuery("u_collection_id", source.u_collectionid);
        u_cmdb_sccm_collection.orderByDesc("sys_updated_on");
        u_cmdb_sccm_collection.setLimit(1);
        u_cmdb_sccm_collection.query();
        if (u_cmdb_sccm_collection.next())
            return u_cmdb_sccm_collection.sys_id + "";
            else{
                ignore = true;
            }
            //log.warn("collection mapping field" + u_cmdb_sccm_collection.sys_id);
    }

    return "";

})(source);
 ---------------------------------------------------------------------------------------------------------------
 
Device: field map script
 
answer = (function transformEntry(source) {

    if (!source.u_resourceid)
        return "";

    var sourceName = "SCCM";
    if (source.sys_import_set.data_source.name && source.sys_import_set.data_source.name.indexOf(" - ") != -1)
        sourceName += "-" + source.sys_import_set.data_source.name.replace(/^.* - /g, "");

    var sys_object_source = new GlideRecord("sys_object_source");
    sys_object_source.addQuery("name", sourceName);
    sys_object_source.addQuery("id", source.u_resourceid);
    sys_object_source.addQuery("target_table", "IN", "cmdb_ci_computer,cmdb_ci_server,cmdb_ci_win_server,cmdb_ci_pc_hardware,u_cmdb_ci_pc_windows,u_cmdb_ci_pc_macos");
    sys_object_source.addNotNullQuery("target_sys_id");
    sys_object_source.query();
    while (sys_object_source.next()) {
        var cmdb_ci = new GlideRecord(sys_object_source.target_table);
        if (cmdb_ci.get(sys_object_source.target_sys_id))
            return cmdb_ci.sys_id + "";
    }

    if (source.u_sitecode) {
        var cmdb_ci_computer = new GlideRecord("cmdb_ci_computer");
        cmdb_ci_computer.addQuery("u_sccm_site.u_site_code", source.u_sitecode);
        cmdb_ci_computer.addQuery("u_sccm_resource_id", source.u_resourceid);
        cmdb_ci_computer.orderByDesc("last_discovered");
        cmdb_ci_computer.setLimit(1);
        cmdb_ci_computer.query();
        if (cmdb_ci_computer.next())
            return cmdb_ci_computer.sys_id + "";
    }

    return "";

})(source);
 
How to avoid the generation of import  logs as its generating 50k logs per day.  ALso, i observed there are duplicate importset rows which could be causing this issue. How do we avoid this.Please suggest.
3 REPLIES 3

Anand Kumar P
Giga Patron

Hi @Rashmi Rao ,

 

Check why duplicates are occurring in your import set table.
Ensure your import set table has unique keys to prevent duplicates.
Review your import process for errors that might create duplicates.

 Add error handling to your scripts to avoid unnecessary logging.

Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand

Rajdeep Ganguly
Mega Guru

The issue you're facing is due to the coalesce fields in your transform map. When you have more than one coalesce field, ServiceNow checks for a match on all coalesce fields. If it finds more than one match, it generates the log message you're seeing. Here are some steps to resolve this issue:

1. **Review Coalesce Fields**: Check if both coalesce fields are necessary. If not, remove the unnecessary one.

2. **Check for Duplicate Records**: As you mentioned, duplicate import set rows could be causing this issue. You can create a script to identify and delete these duplicates.

3. **Modify the Transform Script**: You can modify the transform script to handle multiple matches. For example, you can add a condition to only return the most recent match.

4. **Use a Unique Identifier**: If possible, use a unique identifier as a coalesce field to avoid multiple matches.

5. **Limit the Number of Logs**: You can limit the number of logs generated by modifying the log level in System Logs > Properties.

6. **Clean Up Old Logs**: Regularly clean up old logs to prevent them from taking up too much space.

7. **Optimize the Transform Map**: Review the transform map and optimize it to improve performance and reduce the number of logs generated.

8. **Use Scheduled Jobs**: Schedule the import set to run during off-peak hours to reduce the impact on system performance.

Remember, it's important to thoroughly test any changes in a sub-production instance before applying them to your production instance.


nowKB.com

For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - https://nowgpt.ai/

For the ServiceNow Certified System Administrator exams try this :
https://www.udemy.com/course/servicenow-csa-admin-certification-exam-2023/?couponCode=NOW-DEVELOPER

Why Ai ? @Rajdeep Ganguly 


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect