1. Home
  2. /
  3. Admin Guide
  4. /
  5. Plugins
  6. /
  7. Sirene

Sirene

Introduction

This guide aims to walk you through the process of effectively integrate Sirene with Cirrus Shield.

Prerequisistes

Before you can start using the service, you will need to do the following steps:

In Sirene

1. Create a Sirene Account

Create a Sirene account by signing in to insee.fr website, here is the link: https://api.insee.fr/catalogue/site/themes/wso2/subthemes/insee/pages/item-info.jag?name=Sirene&version=V3&provider=insee

2. Retrieve Application Credentials (Consumer Key & Consumer Secret):

After creating your account, proceed to the “My Applications” section. Click on “Add Application” to create a new application.

Once the application is created, navigate to its name, and access the “Production Keys” tab. Here, you can obtain the Consumer Key & Consumer Secret

In Cirrus Shield

  1. Install the Sirene Plugin:

Go to “Configuration” in Cirrus Shield, then select “Extensions.” Install the Sirene plugin to enable the integration.

  1. Creation of “Account” object:

To use the Sirene Plugin effectively, ensure that the “Account” object is created with specific fields and field types. The essential fields for Sirene integration are “CodeAPE” and “SIRET.” Refer to the images provided below for guidance.

To be able to create an object you must go to Configuration -> Objects and click on the button to create an object

After creating the object, go to “Champs personnalisés” and create a new field, based on the fields that are shown in the image.

N.B. : Make sure to create the fields with the same name and same type of the images regarding the “Account” object

It should be the same done for the rest of the fields based on their name and field types.

3. JavaScript Button :

Create a button for the object that you will be using with Sirene. To be able to create a JavaScript button, you must go to Configuration -> Object -> Details -> Bouton Personnalisés.

Custom Buttons

Ensuite, vous créez un bouton avec les informations suivantes :

Here is the code that you will be using for the button:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<style>
    #myModalList {
        max-height: 700px;
        overflow-y: auto;
    }

    .modal {
        display: none;
        padding-top: 40px;
        width: 100%;
        height: 100%;
        overflow: auto;
        background-color: rgb(0, 0, 0);
        background-color: rgba(0, 0, 0, 0.4);
    }
    .modal-content {
        background-color: #fefefe;
        margin: auto;
        padding: 20px;
        border: 1px solid #888;
        width: 80%;
    }
    .close {
        float: right;
        font-size: 28px;
        font-weight: bold;
    }
    #MySelectBtn {
        float: right;
    }
    .close:hover,
    .close:focus {
        color: #000;
        text-decoration: none;
        cursor: pointer;
    }
    .modalTable {
    font-family: arial, sans-serif;
    border-collapse: collapse;
    width: 100%;
    }
    .modalElem {
    border: 1px solid #dddddd;
    text-align: left;
    padding: 8px;
    }
    .modalRow:nth-child(even) {
    background-color: #dddddd;
    }
    .modalElem label {
    display: inline;
    }
    #MySelectBtn,
    .MyCancel {
        margin-top: 10px;
        padding: 5px 10px;
    }
    #myModalListInfo {
        margin-bottom: 10px;
        padding: 5px;
    }
</style>

<div id="myModal" class="modal">
    <div class="modal-content">
        <span class="close">&times;</span>
        <div id="myModalList" class="table-responsive"></div>
    </div>
</div>
<script>

function GetCompanyInfo() {

    var orgid = GetOrganizationInfo().Id;
    var myRecordId = GetRecordGUID();
    var recordData = GetDataByID(myRecordId, "Account", "Name, Company_Number");
    console.log("record data");
    console.log(recordData);
    if (recordData.Company_Number == null || recordData.Company_Number == "null") {
        var modal = document.getElementById("myModal");
        var modalList = document.getElementById("myModalList");
        console.log("modal list value")
        console.log(modalList)
        var span = document.getElementsByClassName("close")[0];

        span.onclick = function () {
            modal.style.display = "none";
            modalList.innerHTML = "";
        }

        var companies;
        $.ajax({
            type: "GET",
            async: false,
            url: `https://sirene.cirrus-shield.net/Sirene?name=${recordData.Name}&orgid=${orgid}`,
            success: function (Data) {
                if (Data != undefined) {
                    companies = Data;
                    console.log("companies ");
                    console.log(companies);
                    var table = "<table class='modalTable table table-hover'>"
                    var hd = `<thead>
                        <tr class='modalRow'>
                            <th class='modalElem'></th>
                            <th class='modalElem'>SIRET</th>
                            <th class='modalElem'>Nom</th>
                            <th class='modalElem'>ADRESSE</th>
                        </tr>
                    </thead>`;
                    table += hd
                    companies.forEach(company => {
                        console.log("address etablissement")
                        console.log(company.adresseEtablissement);
                        var row = `<tr id=${company.siret} class='modalRow'>
                            <td class='modalElem'><input type="radio" id=${company.siret} name="company" value=${company.siret}></td>
                            <td class='modalElem'>${company.siret}</td>
                            <td class='modalElem'>${company.uniteLegale.denominationUniteLegale}</td>
                            <td class='modalElem'>
                                <label for=${company.siret} id='myLabel'>
                                    ${company.adresseEtablissement.numeroVoieEtablissement ?? ""} ${company.adresseEtablissement.typeVoieEtablissement ?? ""} ${company.adresseEtablissement.libelleVoieEtablissement ?? ""}, ${company.adresseEtablissement.codePostalEtablissement ?? ""} ${company.adresseEtablissement.libelleCommuneEtablissement ?? ""}
                                </label>
                            </td>
                        </tr>`
                        table += row;

                    });
                    table += "</table>"

                    console.log("created table here")
                    var selectBtn = "<input type='button' value='Select' id='MySelectBtn'/>";
                    var cancelBtn = "<input type='button' value='Cancel' class='MyCancel'/>";

                    console.log("adding the showing first n results")
                    modalList.innerHTML += `<div id="myModalListInfo">Showing first <strong>${Object.keys(companies).length < 100 ? Object.keys(companies).length : 100}</strong> results</div>`

                    console.log("adding the table")
                    modalList.innerHTML += table;
                    // console.log("adding the select button")
                    // modalList.innerHTML += selectBtn;
                    // console.log("adding the cancel button")
                    // modalList.innerHTML += cancelBtn;
                    modalList.insertAdjacentHTML('afterend', selectBtn);
                    modalList.insertAdjacentHTML('afterend', cancelBtn);
                    modal.style.display = "block";

                    console.log("getting the MySelectBtn tag")
                    var selBtn = document.getElementById("MySelectBtn");
                    console.log(selBtn);

                    console.log("setting the onclick for MySelectBtn")
                    selBtn.onclick = function () {
                        getSelected(myRecordId, recordData.Name, orgid)
                    };

                    console.log("getting MyCancel tag");
                    var delBtn = document.getElementsByClassName("MyCancel")[0];

                    console.log("setting the onclick for MyCancel")
                    delBtn.onclick = function () {
                        modal.style.display = "none";
                        modalList.innerHTML = "";
                    }
                }
                else {
                    console.log("no companies")
                    companies = null;
                }
            },
            error: function (XMLHttpRequest) {
                alert(XMLHttpRequest.responseText);
            }
        });
        $('.modalTable tbody tr').click(function (event) {
            if (event.target.type !== 'radio') {
                $(':radio', this).trigger('click');
            }
        });
    }
    else {
        addCompanyInfo(recordData.Company_Number, myRecordId, recordData.Name, orgid);
    }
}

function getSelected(myRecordId, name, orgid) {
    var mySiret = document.querySelector("input[name=company]:checked").value;
    console.log("Name of selected record: " + name);
    console.log("Siret of selected record: " + mySiret);
    addCompanyInfo(mySiret, myRecordId, name, orgid);

}

function addCompanyInfo(siret, myRecordId, name, orgid) {
    var companyInfo;
    $.ajax({
        type: "GET",
        async: false,
        url: `https://sirene.cirrus-shield.net/Sirene/${siret}?orgid=${orgid}`,
        success: function (Data) {
            if (Data != undefined) {
                companyInfo = Data;
                console.log(companyInfo);
            }
            else {
                companyInfo = null;
            }
        },
        error: function (XMLHttpRequest) {
            alert(XMLHttpRequest.responseText);
            //var response = JSON.parse(XMLHttpRequest.responseText);
            //console.log(response);
            //if (response.status == 404) {
            //    alert("No company found with this siret: " + siret + ".")
            //}
            //else {
            //    alert(response.title);
            //}
        }
    });
    if (companyInfo != null) {
        name = name.toUpperCase() == companyInfo.uniteLegale.denominationUniteLegale ? name : companyInfo.uniteLegale.denominationUniteLegale;

        var docAcc = document.implementation.createDocument("", "", null);
        var xmlAccData = docAcc.createElement("Data");
        var xmlAcc = docAcc.createElement("Account");
        var element;

    
        element = docAcc.createElement("Id");
        element.textContent = myRecordId;
        xmlAcc.appendChild(element);

        element = docAcc.createElement("Name");
        element.textContent = name;
        xmlAcc.appendChild(element);

        //element = docAcc.createElement("Company_Creation_Date");
        //element.textContent = companyInfo.uniteLegale.dateCreationUniteLegale;
        //xmlAcc.appendChild(element);

        element = docAcc.createElement("Nom_du_dirigeant");
        element.textContent = companyInfo.uniteLegale.nomUniteLegale ?? "";
        xmlAcc.appendChild(element);

        element = docAcc.createElement("Prenom_du_dirigeant");
        element.textContent = companyInfo.uniteLegale.prenom1UniteLegale ?? "";
        xmlAcc.appendChild(element);

        element = docAcc.createElement("Code_NAF");
        element.textContent = companyInfo.uniteLegale.activitePrincipaleUniteLegale ?? "";
        xmlAcc.appendChild(element);

        element = docAcc.createElement("Effectifs");
        element.textContent = companyInfo.uniteLegale.trancheEffectifsUniteLegale;
        xmlAcc.appendChild(element);

        element = docAcc.createElement("Company_Number");
        element.textContent = siret;
        xmlAcc.appendChild(element);

        element = docAcc.createElement("Billing_Street");
        element.textContent = `${companyInfo.adresseEtablissement.numeroVoieEtablissement ?? ""} ${companyInfo.adresseEtablissement.typeVoieEtablissement ?? ""} ${companyInfo.adresseEtablissement.libelleVoieEtablissement ?? ""}`;
        xmlAcc.appendChild(element);

        console.log(companyInfo.adresseEtablissement.libelleCommuneEtablissement);
        element = docAcc.createElement("Billing_City");
        element.textContent = companyInfo.adresseEtablissement.libelleCommuneEtablissement ?? "";
        xmlAcc.appendChild(element);

        element = docAcc.createElement("Billing_Country");
        element.textContent = "France";
        xmlAcc.appendChild(element);

        element = docAcc.createElement("Billing_ZIP");
        element.textContent = companyInfo.adresseEtablissement.codePostalEtablissement ?? "";
        xmlAcc.appendChild(element);

        xmlAccData.appendChild(xmlAcc);
        docAcc.appendChild(xmlAccData);


        try {
            // Update account
            console.log("###   UPDATING ACCOUNT  ###\n" + (new XMLSerializer()).serializeToString(docAcc));
            var ObjResAcc = UpdateRecord("Account", "Id", docAcc, false)
            if (!ObjResAcc.msgSuccess) {
                alert(ObjResAcc.msgInfo);
                return;
            }
            console.log("###   UPDATING ACCOUNT SERVER RESPONSE   ###\n" + ObjResAcc.msgInfo);
            location = location;
        } catch (ex) {
            var errorMsg = "An error happened while updating the account.\n " + ex.message;
            alert(errorMsg);
            return;
        }
    }
}
</script>


Make sure to change the visibility of the button based on the users that will be using it, you can do this by going to the object where you created the button -> button details -> Profils

And finally, you will be able to see the button in the details page of the record of the specific chosen object

Configuration

To configure the plugin that you installed, you’ll have to go to the details of the Sirene installed plugin.

You will be navigated to the configuration page, start by adding your cirrus-shield credentials (Username & Password), your Sirene credentials (Access Token), you can also click on the check box if you want to get info about new companies in France daily, and the CodeAPE of your choice, you can input one or more based on your preferences, and then click on create, your configuration will be saved to Cirrus-Shield.

Was this article helpful to you? No Yes

How can we help?