int ResourceDebugInterface::getCount(const QString &module) const { SugarSession *session = mResource->mSession; KDSoapGenerated::Sugarsoap *soap = session->soap(); const QString sessionId = session->sessionId(); if (sessionId.isEmpty()) { qCWarning(FATCRM_SUGARCRMRESOURCE_LOG) << "No session! Need to login first."; } // for notes and emails, use this: //const QString query = QString("parent_type=\"Opportunities\""); const QString query = QString(); KDSoapGenerated::TNS__Get_entries_count_result response = soap->get_entries_count(sessionId, module, query, 0); qCDebug(FATCRM_SUGARCRMRESOURCE_LOG) << response.result_count() << "entries"; // Let's also take a peek at the first entry KDSoapGenerated::TNS__Select_fields fields; fields.setItems(availableFields(module)); const auto listResponse = soap->get_entry_list(sessionId, module, query, QString() /*orderBy*/, 0 /*offset*/, fields, {}, 1 /*maxResults*/, 0 /*fetchDeleted*/, false /*favorites*/); const QList<KDSoapGenerated::TNS__Entry_value> items = listResponse.entry_list().items(); if (!items.isEmpty()) { QList<KDSoapGenerated::TNS__Name_value> values = items.at(0).name_value_list().items(); Q_FOREACH (const KDSoapGenerated::TNS__Name_value &value, values) { qCDebug(FATCRM_SUGARCRMRESOURCE_LOG) << value.name() << "=" << value.value(); }
void ModuleHandler::listEntries(const ListEntriesScope &scope) { const QString query = scope.query(queryStringForListing(), mModuleName.toLower()); const QString orderBy = orderByForListing(); const int offset = scope.offset(); const int maxResults = 100; const int fetchDeleted = scope.deleted(); KDSoapGenerated::TNS__Select_fields selectedFields; selectedFields.setItems(supportedSugarFields()); soap()->asyncGet_entry_list(sessionId(), moduleName(), query, orderBy, offset, selectedFields, maxResults, fetchDeleted); }
void DocumentsHandler::getExtraInformation(Akonadi::Item::List &items) { for (int pos = 0; pos < items.count(); ++pos) { Akonadi::Item &item = items[pos]; if (!item.hasPayload<SugarDocument>()) { qCCritical(FATCRM_SUGARCRMRESOURCE_LOG) << "item (id=" << item.id() << ", remoteId=" << item.remoteId() << ", mime=" << item.mimeType() << ") is missing Document payload"; continue; } SugarDocument document = item.payload<SugarDocument>(); bool update = false; KDSoapGenerated::TNS__Select_fields selectedFields; selectedFields.setItems({QStringLiteral("id")}); // Get the Account(s) related to this document // http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_6.5/Application_Framework/Web_Services/Method_Calls/get_relationships/ // http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_6.5/Application_Framework/Web_Services/Examples/REST/PHP/Retrieving_Related_Records/ KDSoapGenerated::TNS__Get_entry_result_version2 result = mSession->soap()->get_relationships(sessionId(), QStringLiteral("Documents"), document.id(), moduleToName(Module::Accounts).toLower(), {}, selectedFields, {}, 0 /*deleted*/, QString(), 0 /*offset*/, 0 /*limit*/); QStringList linkedAccountIds; Q_FOREACH (const KDSoapGenerated::TNS__Entry_value& entry, result.entry_list().items()) { linkedAccountIds.append(entry.id()); } if (!linkedAccountIds.isEmpty()) { document.setLinkedAccountIds(linkedAccountIds); update = true; } QStringList linkedOpportunityIds; result = mSession->soap()->get_relationships(sessionId(), QStringLiteral("Documents"), document.id(), moduleToName(Module::Opportunities).toLower(), {}, selectedFields, {}, 0 /*deleted*/, QString(), 0 /*offset*/, 0 /*limit*/); Q_FOREACH (const KDSoapGenerated::TNS__Entry_value &entry, result.entry_list().items()) { linkedOpportunityIds.append(entry.id()); } if (!linkedOpportunityIds.isEmpty()) { document.setLinkedOpportunityIds(linkedOpportunityIds); update = true; } if (update) { item.setPayload<SugarDocument>(document); } } }